Ticket #13085: generic.py.diff
File generic.py.diff, 1.2 KB (added by , 15 years ago) |
---|
-
django/contrib/contenttypes/generic.py
49 49 # Convenience function using get_model avoids a circular import when 50 50 # using this model 51 51 ContentType = get_model("contenttypes", "contenttype") 52 if obj :52 if obj is not None: 53 53 return ContentType.objects.db_manager(obj._state.db).get_for_model(obj) 54 elif id :54 elif id is not None: 55 55 return ContentType.objects.db_manager(using).get_for_id(id) 56 56 else: 57 57 # This should never happen. I love comments like this, don't you? … … 72 72 # performance when dealing with GFKs in loops and such. 73 73 f = self.model._meta.get_field(self.ct_field) 74 74 ct_id = getattr(instance, f.get_attname(), None) 75 if ct_id :75 if ct_id is not None: 76 76 ct = self.get_content_type(id=ct_id, using=instance._state.db) 77 77 try: 78 78 rel_obj = ct.get_object_for_this_type(pk=getattr(instance, self.fk_field))