Ticket #14492: django-14492.diff

File django-14492.diff, 1.3 KB (added by Alex Gaynor, 14 years ago)
  • django/db/models/base.py

    diff --git a/django/db/models/base.py b/django/db/models/base.py
    index 6077f56..e9db687 100644
    a b class Model(object):  
    370370        return '%s object' % self.__class__.__name__
    371371
    372372    def __eq__(self, other):
    373         return isinstance(other, self.__class__) and self._get_pk_val() == other._get_pk_val()
     373        if isinstance(other, self.__class__):
     374            return self.pk == other.pk
     375        return NotImplemented
    374376
    375377    def __ne__(self, other):
    376         return not self.__eq__(other)
     378        return not self == other
    377379
    378380    def __hash__(self):
    379381        return hash(self._get_pk_val())
  • tests/modeltests/proxy_models/tests.py

    diff --git a/tests/modeltests/proxy_models/tests.py b/tests/modeltests/proxy_models/tests.py
    index 346a2a3..32bdc83 100644
    a b class ProxyModelTests(TestCase):  
    312312        management.call_command('loaddata', 'mypeople.json', verbosity=0, commit=False)
    313313        p = MyPerson.objects.get(pk=100)
    314314        self.assertEqual(p.name, 'Elvis Presley')
     315
     316    def test_eq(self):
     317        s = State(pk=3)
     318        sp = StateProxy(pk=3)
     319        self.assertEqual(s, sp)
     320        self.assertEqual(sp, s)
     321        sp = StateProxy(pk=4)
     322        self.assertNotEqual(s, sp)
     323        self.assertNotEqual(sp, s)
Back to Top