Added Document.reload method

This commit is contained in:
Harry Marr
2010-01-05 00:25:42 +00:00
parent 5ca75e9c6d
commit 3bead80f96
3 changed files with 29 additions and 2 deletions

View File

@@ -64,6 +64,14 @@ class Document(BaseDocument):
object_id = self._fields['id'].to_mongo(self.id)
self.__class__.objects(id=object_id).delete()
def reload(self):
"""Reloads all attributes from the database.
"""
object_id = self._fields['id'].to_mongo(self.id)
obj = self.__class__.objects(id=object_id).first()
for field in self._fields:
setattr(self, field, getattr(obj, field))
def validate(self):
"""Ensure that all fields' values are valid and that required fields
are present.