Implemented equality between Documents and DBRefs

This commit is contained in:
tprimozi
2014-02-04 13:41:17 +00:00
parent d4b3649640
commit c5c7378c63
3 changed files with 30 additions and 3 deletions

View File

@@ -214,8 +214,9 @@ class BaseDocument(object):
def __eq__(self, other):
if isinstance(other, self.__class__) and hasattr(other, 'id'):
if self.id == other.id:
return True
return self.id == other.id
if isinstance(other, DBRef):
return self.id == other.id
return False
def __ne__(self, other):

View File

@@ -67,7 +67,7 @@ class EmbeddedDocument(BaseDocument):
def __eq__(self, other):
if isinstance(other, self.__class__):
return self.to_mongo() == other.to_mongo()
return self._data == other._data
return False
def __ne__(self, other):