Added Document.reload method
This commit is contained in:
parent
5ca75e9c6d
commit
3bead80f96
3 changed files with 29 additions and 2 deletions
|
|
@ -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.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue