parent
8b97808931
commit
fdc385ea33
1
AUTHORS
1
AUTHORS
@ -78,3 +78,4 @@ that much better:
|
|||||||
* jonrscott
|
* jonrscott
|
||||||
* Alice Zoë Bevan-McGregor
|
* Alice Zoë Bevan-McGregor
|
||||||
* Stephen Young
|
* Stephen Young
|
||||||
|
* tkloc
|
||||||
|
@ -5,6 +5,7 @@ Changelog
|
|||||||
Changes in dev
|
Changes in dev
|
||||||
==============
|
==============
|
||||||
|
|
||||||
|
- Fixed deletion of dynamic data
|
||||||
- Added support for the $elementMatch operator
|
- Added support for the $elementMatch operator
|
||||||
- Added reverse option to SortedListFields
|
- Added reverse option to SortedListFields
|
||||||
- Fixed dereferencing - multi directional list dereferencing
|
- Fixed dereferencing - multi directional list dereferencing
|
||||||
|
@ -329,6 +329,15 @@ class DynamicDocument(Document):
|
|||||||
__metaclass__ = TopLevelDocumentMetaclass
|
__metaclass__ = TopLevelDocumentMetaclass
|
||||||
_dynamic = True
|
_dynamic = True
|
||||||
|
|
||||||
|
def __delattr__(self, *args, **kwargs):
|
||||||
|
"""Deletes the attribute by setting to None and allowing _delta to unset
|
||||||
|
it"""
|
||||||
|
field_name = args[0]
|
||||||
|
if field_name in self._dynamic_fields:
|
||||||
|
setattr(self, field_name, None)
|
||||||
|
else:
|
||||||
|
super(DynamicDocument, self).__delattr__(*args, **kwargs)
|
||||||
|
|
||||||
|
|
||||||
class DynamicEmbeddedDocument(EmbeddedDocument):
|
class DynamicEmbeddedDocument(EmbeddedDocument):
|
||||||
"""A Dynamic Embedded Document class allowing flexible, expandable and
|
"""A Dynamic Embedded Document class allowing flexible, expandable and
|
||||||
|
@ -50,6 +50,33 @@ class DynamicDocTest(unittest.TestCase):
|
|||||||
p = self.Person.objects.get()
|
p = self.Person.objects.get()
|
||||||
self.assertEquals(p.misc, {'hello': 'world'})
|
self.assertEquals(p.misc, {'hello': 'world'})
|
||||||
|
|
||||||
|
def test_delete_dynamic_field(self):
|
||||||
|
"""Test deleting a dynamic field works"""
|
||||||
|
self.Person.drop_collection()
|
||||||
|
p = self.Person()
|
||||||
|
p.name = "Dean"
|
||||||
|
p.misc = 22
|
||||||
|
p.save()
|
||||||
|
|
||||||
|
p = self.Person.objects.get()
|
||||||
|
p.misc = {'hello': 'world'}
|
||||||
|
p.save()
|
||||||
|
|
||||||
|
p = self.Person.objects.get()
|
||||||
|
self.assertEquals(p.misc, {'hello': 'world'})
|
||||||
|
collection = self.db[self.Person._get_collection_name()]
|
||||||
|
obj = collection.find_one()
|
||||||
|
self.assertEquals(sorted(obj.keys()), ['_cls', '_id', '_types', 'misc', 'name'])
|
||||||
|
|
||||||
|
del(p.misc)
|
||||||
|
p.save()
|
||||||
|
|
||||||
|
p = self.Person.objects.get()
|
||||||
|
self.assertFalse(hasattr(p, 'misc'))
|
||||||
|
|
||||||
|
obj = collection.find_one()
|
||||||
|
self.assertEquals(sorted(obj.keys()), ['_cls', '_id', '_types', 'name'])
|
||||||
|
|
||||||
def test_dynamic_document_queries(self):
|
def test_dynamic_document_queries(self):
|
||||||
"""Ensure we can query dynamic fields"""
|
"""Ensure we can query dynamic fields"""
|
||||||
p = self.Person()
|
p = self.Person()
|
||||||
|
Loading…
x
Reference in New Issue
Block a user