Merge pull request #567 from tomprimozic/master

Implemented equality between Documents and DBRefs
This commit is contained in:
Ross Lawley
2014-06-27 11:37:24 +01:00
3 changed files with 64 additions and 3 deletions

View File

@@ -229,8 +229,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._get_collection_name() == other.collection and self.id == other.id
return False
def __ne__(self, other):

View File

@@ -69,7 +69,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):