Added to_dbref

Thanks to Ankhbayar for the initial code
Closes #202
This commit is contained in:
Ross Lawley
2011-06-17 10:34:29 +01:00
parent 5e7efcc8c2
commit f3d265bbe0
2 changed files with 16 additions and 0 deletions

View File

@@ -167,6 +167,14 @@ class Document(BaseDocument):
value._changed_fields = []
return value
def to_dbref(self):
"""Returns an instance of :class:`~pymongo.dbref.DBRef` useful in
`__raw__` queries."""
if not self.pk:
msg = "Only saved documents can have a valid dbref"
raise OperationError(msg)
return pymongo.dbref.DBRef(self.__class__._meta['collection'], self.pk)
@classmethod
def register_delete_rule(cls, document_cls, field_name, rule):
"""This method registers the delete rules to apply when removing this