support multiple operator #1510
This commit is contained in:
parent
2f1fe5468e
commit
b9e922c658
1
AUTHORS
1
AUTHORS
@ -243,3 +243,4 @@ that much better:
|
||||
* Victor Varvaryuk
|
||||
* Stanislav Kaledin (https://github.com/sallyruthstruik)
|
||||
* Dmitry Yantsen (https://github.com/mrTable)
|
||||
* Erdenezul Batmunkh (https://github.com/erdenezul)
|
||||
|
@ -3,9 +3,10 @@ from mongoengine.errors import NotRegistered
|
||||
__all__ = ('UPDATE_OPERATORS', 'get_document', '_document_registry')
|
||||
|
||||
|
||||
UPDATE_OPERATORS = set(['set', 'unset', 'inc', 'dec', 'pop', 'push',
|
||||
'push_all', 'pull', 'pull_all', 'add_to_set',
|
||||
'set_on_insert', 'min', 'max', 'rename'])
|
||||
UPDATE_OPERATORS = set(['set', 'unset', 'inc', 'dec', 'mul',
|
||||
'pop', 'push', 'push_all', 'pull',
|
||||
'pull_all', 'add_to_set', 'set_on_insert',
|
||||
'min', 'max', 'rename'])
|
||||
|
||||
|
||||
_document_registry = {}
|
||||
|
@ -589,6 +589,20 @@ class QuerySetTest(unittest.TestCase):
|
||||
Scores.objects(id=scores.id).update(max__high_score=500)
|
||||
self.assertEqual(Scores.objects.get(id=scores.id).high_score, 1000)
|
||||
|
||||
@needs_mongodb_v26
|
||||
def test_update_multiple(self):
|
||||
class Product(Document):
|
||||
item = StringField()
|
||||
price = FloatField()
|
||||
|
||||
product = Product.objects.create(item='ABC', price=10.99)
|
||||
product = Product.objects.create(item='ABC', price=10.99)
|
||||
Product.objects(id=product.id).update(mul__price=1.25)
|
||||
self.assertEqual(Product.objects.get(id=product.id).price, 13.7375)
|
||||
unknown_product = Product.objects.create(item='Unknown')
|
||||
Product.objects(id=unknown_product.id).update(mul__price=100)
|
||||
self.assertEqual(Product.objects.get(id=unknown_product.id).price, 0)
|
||||
|
||||
def test_updates_can_have_match_operators(self):
|
||||
|
||||
class Comment(EmbeddedDocument):
|
||||
|
Loading…
x
Reference in New Issue
Block a user