Skip to content

Commit

Permalink
Merge pull request #917 from DavidBord/fix-595
Browse files Browse the repository at this point in the history
Fix #595: Support += and *= for ListField
  • Loading branch information
DavidBord committed Apr 1, 2015
2 parents cbd2a44 + de0e558 commit 1001f1b
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 0 deletions.
4 changes: 4 additions & 0 deletions docs/changelog.rst
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,10 @@ Changelog

Changes in 0.9.X - DEV
======================
- Support += and *= for ListField #595
Changes in 0.9.0
================
- Update FileField when creating a new file #714
- Added `EmbeddedDocumentListField` for Lists of Embedded Documents. #826
- ComplexDateTimeField should fall back to None when null=True #864
Expand Down
8 changes: 8 additions & 0 deletions mongoengine/base/datastructures.py
Original file line number Diff line number Diff line change
Expand Up @@ -156,6 +156,14 @@ def __setstate__(self, state):
self = state
return self

def __iadd__(self, other):
self._mark_as_changed()
return super(BaseList, self).__iadd__(other)

def __imul__(self, other):
self._mark_as_changed()
return super(BaseList, self).__imul__(other)

def append(self, *args, **kwargs):
self._mark_as_changed()
return super(BaseList, self).append(*args, **kwargs)
Expand Down
12 changes: 12 additions & 0 deletions tests/fields/fields.py
Original file line number Diff line number Diff line change
Expand Up @@ -946,6 +946,18 @@ class BlogPost(Document):
BlogPost.objects.filter(info__0__test__exact='5').count(), 0)
self.assertEqual(
BlogPost.objects.filter(info__100__test__exact='test').count(), 0)

post = BlogPost()
post.info = ['1', '2']
post.save()
post = BlogPost.objects(info=['1', '2']).get()
post.info += ['3', '4']
post.save()
self.assertEqual(BlogPost.objects(info=['1', '2', '3', '4']).count(), 1)
post = BlogPost.objects(info=['1', '2', '3', '4']).get()
post.info *= 2
post.save()
self.assertEqual(BlogPost.objects(info=['1', '2', '3', '4', '1', '2', '3', '4']).count(), 1)
BlogPost.drop_collection()

def test_list_field_passed_in_value(self):
Expand Down

0 comments on commit 1001f1b

Please sign in to comment.