Fixed ListField setslice and delslice dirty tracking (#390)
This commit is contained in:
parent
0cb4070364
commit
7cb46d0761
3
AUTHORS
3
AUTHORS
@ -170,4 +170,5 @@ that much better:
|
|||||||
* Nigel McNie (https://github.com/nigelmcnie)
|
* Nigel McNie (https://github.com/nigelmcnie)
|
||||||
* ygbourhis (https://github.com/ygbourhis)
|
* ygbourhis (https://github.com/ygbourhis)
|
||||||
* Bob Dickinson (https://github.com/BobDickinson)
|
* Bob Dickinson (https://github.com/BobDickinson)
|
||||||
* Michael Bartnett (https://github.com/michaelbartnett)
|
* Michael Bartnett (https://github.com/michaelbartnett)
|
||||||
|
* Alon Horev (https://github.com/alonho)
|
@ -4,6 +4,7 @@ Changelog
|
|||||||
|
|
||||||
Changes in 0.8.3
|
Changes in 0.8.3
|
||||||
================
|
================
|
||||||
|
- Fixed ListField setslice and delslice dirty tracking (#390)
|
||||||
- Added Django 1.5 PY3 support (#392)
|
- Added Django 1.5 PY3 support (#392)
|
||||||
- Added match ($elemMatch) support for EmbeddedDocuments (#379)
|
- Added match ($elemMatch) support for EmbeddedDocuments (#379)
|
||||||
- Fixed weakref being valid after reload (#374)
|
- Fixed weakref being valid after reload (#374)
|
||||||
|
@ -108,6 +108,14 @@ class BaseList(list):
|
|||||||
self._mark_as_changed()
|
self._mark_as_changed()
|
||||||
return super(BaseList, self).__delitem__(*args, **kwargs)
|
return super(BaseList, self).__delitem__(*args, **kwargs)
|
||||||
|
|
||||||
|
def __setslice__(self, *args, **kwargs):
|
||||||
|
self._mark_as_changed()
|
||||||
|
return super(BaseList, self).__setslice__(*args, **kwargs)
|
||||||
|
|
||||||
|
def __delslice__(self, *args, **kwargs):
|
||||||
|
self._mark_as_changed()
|
||||||
|
return super(BaseList, self).__delslice__(*args, **kwargs)
|
||||||
|
|
||||||
def __getstate__(self):
|
def __getstate__(self):
|
||||||
self.instance = None
|
self.instance = None
|
||||||
self._dereferenced = False
|
self._dereferenced = False
|
||||||
|
@ -1018,6 +1018,32 @@ class FieldTest(unittest.TestCase):
|
|||||||
e.mapping = {}
|
e.mapping = {}
|
||||||
self.assertEqual([], e._changed_fields)
|
self.assertEqual([], e._changed_fields)
|
||||||
|
|
||||||
|
def test_slice_marks_field_as_changed(self):
|
||||||
|
|
||||||
|
class Simple(Document):
|
||||||
|
widgets = ListField()
|
||||||
|
|
||||||
|
simple = Simple(widgets=[1, 2, 3, 4]).save()
|
||||||
|
simple.widgets[:3] = []
|
||||||
|
self.assertEqual(['widgets'], simple._changed_fields)
|
||||||
|
simple.save()
|
||||||
|
|
||||||
|
simple = simple.reload()
|
||||||
|
self.assertEqual(simple.widgets, [4])
|
||||||
|
|
||||||
|
def test_del_slice_marks_field_as_changed(self):
|
||||||
|
|
||||||
|
class Simple(Document):
|
||||||
|
widgets = ListField()
|
||||||
|
|
||||||
|
simple = Simple(widgets=[1, 2, 3, 4]).save()
|
||||||
|
del simple.widgets[:3]
|
||||||
|
self.assertEqual(['widgets'], simple._changed_fields)
|
||||||
|
simple.save()
|
||||||
|
|
||||||
|
simple = simple.reload()
|
||||||
|
self.assertEqual(simple.widgets, [4])
|
||||||
|
|
||||||
def test_list_field_complex(self):
|
def test_list_field_complex(self):
|
||||||
"""Ensure that the list fields can handle the complex types."""
|
"""Ensure that the list fields can handle the complex types."""
|
||||||
|
|
||||||
|
Loading…
x
Reference in New Issue
Block a user