Ticket #11892: 11892.deferred_model_eq.diff
File 11892.deferred_model_eq.diff, 1.6 KB (added by , 15 years ago) |
---|
-
tests/modeltests/defer/models.py
183 183 >>> obj.name = "bb" 184 184 >>> obj.save() 185 185 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 192 True 193 >>> s2 == s1 194 True 195 >>> s2 == s3 196 True 197 >>> s3 == s2 198 True 199 186 200 # Finally, we need to flush the app cache for the defer module. 187 201 # Using only/defer creates some artifical entries in the app cache 188 202 # that messes up later tests. Purge all entries, just to be sure. -
django/db/models/base.py
336 336 return '%s object' % self.__class__.__name__ 337 337 338 338 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() 340 346 341 347 def __ne__(self, other): 342 348 return not self.__eq__(other)