Code

Ticket #14492: model_eq_14233.diff

File model_eq_14233.diff, 1.0 KB (added by bruth, 4 years ago)
Line 
1Index: django/db/models/base.py
2===================================================================
3--- django/db/models/base.py    (revision 14233)
4+++ django/db/models/base.py    (working copy)
5@@ -370,8 +370,20 @@
6         return '%s object' % self.__class__.__name__
7 
8     def __eq__(self, other):
9-        return isinstance(other, self.__class__) and self._get_pk_val() == other._get_pk_val()
10+        if isinstance(other, self.__class__):
11+            return self._get_pk_val() == other._get_pk_val()
12 
13+        # self is proxy, other is not
14+        proxy = self._meta.proxy_for_model
15+        if self._meta.proxy is True and isinstance(other, proxy):
16+            return self._get_pk_val() == other._get_pk_val()
17+
18+        # other is proxy, self is not
19+        proxy = other._meta.proxy_for_model
20+        if other._meta.proxy is True and isinstance(self, proxy):
21+            return self._get_pk_val() == other._get_pk_val()
22+        return False
23+
24     def __ne__(self, other):
25         return not self.__eq__(other)
26