Ticket #11892: 11892.deferred_model_eq.diff

File 11892.deferred_model_eq.diff, 1.6 KB (added by Johannes Dollinger, 13 years ago)
  • tests/modeltests/defer/models.py

     
    183183>>> obj.name = "bb"
    184184>>> obj.save()
    185185
     186# Model instances of the same type and same ID are considered equal
     187# make sure this is true for deferred models as well
     188>>> s1 = Secondary.objects.get(first='x1')
     189>>> s2 = Secondary.objects.defer('first').get(pk=s1.pk)
     190>>> s3 = Secondary.objects.defer('second').get(pk=s1.pk)
     191>>> s1 == s2
     192True
     193>>> s2 == s1
     194True
     195>>> s2 == s3
     196True
     197>>> s3 == s2
     198True
     199
    186200# Finally, we need to flush the app cache for the defer module.
    187201# Using only/defer creates some artifical entries in the app cache
    188202# that messes up later tests. Purge all entries, just to be sure.
  • django/db/models/base.py

     
    336336        return '%s object' % self.__class__.__name__
    337337
    338338    def __eq__(self, other):
    339         return isinstance(other, self.__class__) and self._get_pk_val() == other._get_pk_val()
     339        self_model = self.__class__
     340        other_model = other.__class__
     341        if self_model._deferred:
     342            self_model = self_model.__bases__[0]
     343        if getattr(other_model, '_deferred', False):
     344            other_model = other_model.__bases__[0]
     345        return issubclass(other_model, self_model) and self._get_pk_val() == other._get_pk_val()
    340346
    341347    def __ne__(self, other):
    342348        return not self.__eq__(other)
Back to Top