Allow dynamic data to be deleted

Fixes #374
This commit is contained in:
Ross Lawley
2011-11-30 03:06:46 -08:00
parent 8b97808931
commit fdc385ea33
4 changed files with 38 additions and 0 deletions

View File

@@ -329,6 +329,15 @@ class DynamicDocument(Document):
__metaclass__ = TopLevelDocumentMetaclass
_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):
"""A Dynamic Embedded Document class allowing flexible, expandable and