Merge pull request #412 from faulkner/dict-update

Add dict.update() support to BaseDict.

Thx Faulkner :)
This commit is contained in:
Ross Lawley 2012-01-16 03:32:45 -08:00
commit 6bad4bd415
2 changed files with 11 additions and 0 deletions

View File

@ -1293,6 +1293,10 @@ class BaseDict(dict):
self._mark_as_changed()
super(BaseDict, self).popitem(*args, **kwargs)
def update(self, *args, **kwargs):
self._mark_as_changed()
super(BaseDict, self).update(*args, **kwargs)
def _mark_as_changed(self):
if hasattr(self._instance, '_mark_as_changed'):
self._instance._mark_as_changed(self._name)

View File

@ -772,6 +772,13 @@ class FieldTest(unittest.TestCase):
# Confirm handles non strings or non existing keys
self.assertEquals(BlogPost.objects.filter(info__details__test__exact=5).count(), 0)
self.assertEquals(BlogPost.objects.filter(info__made_up__test__exact='test').count(), 0)
post = BlogPost.objects.create(info={'title': 'original'})
post.info.update({'title': 'updated'})
post.save()
post.reload()
self.assertEquals('updated', post.info['title'])
BlogPost.drop_collection()
def test_dictfield_strict(self):