Merge branch 'master' of http://github.com/sibsibsib/mongoengine into v0.4
Conflicts: mongoengine/queryset.py tests/queryset.py
This commit is contained in:
commit
4c68bc6c96
@ -721,7 +721,7 @@ class QuerySet(object):
|
||||
"""Transform an update spec from Django-style format to Mongo format.
|
||||
"""
|
||||
operators = ['set', 'unset', 'inc', 'dec', 'pop', 'push', 'push_all',
|
||||
'pull', 'pull_all']
|
||||
'pull', 'pull_all', 'add_to_set']
|
||||
|
||||
mongo_update = {}
|
||||
for key, value in update.items():
|
||||
@ -739,7 +739,9 @@ class QuerySet(object):
|
||||
op = 'inc'
|
||||
if value > 0:
|
||||
value = -value
|
||||
|
||||
elif op == 'add_to_set':
|
||||
op = op.replace('_to_set', 'ToSet')
|
||||
|
||||
if _doc_cls:
|
||||
# Switch field names to proper names [set in Field(name='foo')]
|
||||
fields = QuerySet._lookup_field(_doc_cls, parts)
|
||||
@ -747,7 +749,8 @@ class QuerySet(object):
|
||||
|
||||
# Convert value to proper value
|
||||
field = fields[-1]
|
||||
if op in (None, 'set', 'unset', 'pop', 'push', 'pull'):
|
||||
if op in (None, 'set', 'unset', 'pop', 'push', 'pull',
|
||||
'addToSet'):
|
||||
value = field.prepare_query_value(op, value)
|
||||
elif op in ('pushAll', 'pullAll'):
|
||||
value = [field.prepare_query_value(op, v) for v in value]
|
||||
|
@ -717,6 +717,11 @@ class QuerySetTest(unittest.TestCase):
|
||||
post.reload()
|
||||
self.assertEqual(post.tags, tags)
|
||||
|
||||
BlogPost.objects.update_one(add_to_set__tags='unique')
|
||||
BlogPost.objects.update_one(add_to_set__tags='unique')
|
||||
post.reload()
|
||||
self.assertEqual(post.tags.count('unique'), 1)
|
||||
|
||||
BlogPost.drop_collection()
|
||||
|
||||
def test_update_pull(self):
|
||||
|
Loading…
x
Reference in New Issue
Block a user