updating equality operations to stop relying on the to_database dictionary conversion

This commit is contained in:
Blake Eggleston
2013-06-25 15:34:35 -07:00
parent 044e9fb933
commit e722b50546

View File

@@ -186,7 +186,21 @@ class BaseModel(object):
return cls._columns[name]
def __eq__(self, other):
return self.as_dict() == other.as_dict()
if self.__class__ != other.__class__:
return False
# check attribute keys
keys = set(self._columns.keys())
other_keys = set(self._columns.keys())
if keys != other_keys:
return False
# check that all of the attributes match
for key in other_keys:
if getattr(self, key, None) != getattr(other, key, None):
return False
return True
def __ne__(self, other):
return not self.__eq__(other)