Ticket #16917: 16917.diff

File 16917.diff, 1.6 KB (added by Ivan Sagalaev, 13 years ago)

Patch

  • django/contrib/contenttypes/models.py

    === modified file 'django/contrib/contenttypes/models.py'
     
    9292        #
    9393        # We return self.name only when users have changed its value from the
    9494        # initial verbose_name_raw and might rely on it.
    95         meta = self.model_class()._meta
    96         if self.name != meta.verbose_name_raw:
     95        model = self.model_class()
     96        if not model or self.name != model._meta.verbose_name_raw:
    9797            return self.name
    9898        else:
    99             return force_unicode(meta.verbose_name)
     99            return force_unicode(model._meta.verbose_name)
    100100
    101101    def model_class(self):
    102102        "Returns the Python model class for this type of content."
  • django/contrib/contenttypes/tests.py

    === modified file 'django/contrib/contenttypes/tests.py'
     
    109109        obj = FooWithoutUrl.objects.create(name="john")
    110110
    111111        self.assertRaises(Http404, shortcut, request, user_ct.id, obj.id)
     112
     113    def test_missing_model(self):
     114        """
     115        Ensures that displaying content types in admin (or anywhere) doesn't
     116        break on leftover content type records in the DB for which no model
     117        is defined anymore.
     118        """
     119        ct = ContentType.objects.create(
     120            name = 'Old model',
     121            app_label = 'contenttypes',
     122            model = 'OldModel',
     123        )
     124        self.assertEqual(unicode(ct), u'Old model')
Back to Top