Skip to content

Instantly share code, notes, and snippets.

@EnTeQuAk
Created February 23, 2016 09:31
Show Gist options
  • Save EnTeQuAk/6c67bc978f976b81ab50 to your computer and use it in GitHub Desktop.
Save EnTeQuAk/6c67bc978f976b81ab50 to your computer and use it in GitHub Desktop.
def __eq__(self, other):
- return isinstance(other, self.__class__) and self._get_pk_val() == other._get_pk_val()
+ if not isinstance(other, Model):
+ return False
+ if self._meta.concrete_model != other._meta.concrete_model:
+ return False
+ my_pk = self._get_pk_val()
+ if my_pk is None:
+ return self is other
+ return my_pk == other._get_pk_val()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment