Added Document.reload method
This commit is contained in:
@@ -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.
|
||||
|
||||
Reference in New Issue
Block a user