Ticket #13085: generic.py.diff

File generic.py.diff, 1.2 KB (added by Ben, 15 years ago)
  • django/contrib/contenttypes/generic.py

     
    4949        # Convenience function using get_model avoids a circular import when
    5050        # using this model
    5151        ContentType = get_model("contenttypes", "contenttype")
    52         if obj:
     52        if obj is not None:
    5353             return ContentType.objects.db_manager(obj._state.db).get_for_model(obj)
    54         elif id:
     54        elif id is not None:
    5555             return ContentType.objects.db_manager(using).get_for_id(id)
    5656        else:
    5757            # This should never happen. I love comments like this, don't you?
     
    7272            # performance when dealing with GFKs in loops and such.
    7373            f = self.model._meta.get_field(self.ct_field)
    7474            ct_id = getattr(instance, f.get_attname(), None)
    75             if ct_id:
     75            if ct_id is not None:
    7676                ct = self.get_content_type(id=ct_id, using=instance._state.db)
    7777                try:
    7878                    rel_obj = ct.get_object_for_this_type(pk=getattr(instance, self.fk_field))
Back to Top