Ticket #13137: allow_contenttype_id_0.patch

File allow_contenttype_id_0.patch, 1.1 KB (added by Justin de Vesine, 15 years ago)

Initial proposed patch

  • django/contrib/contenttypes/generic.py

     
    5151        ContentType = get_model("contenttypes", "contenttype")
    5252        if obj:
    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