=== modified file 'django/contrib/contenttypes/models.py'
|
|
|
92 | 92 | # |
93 | 93 | # We return self.name only when users have changed its value from the |
94 | 94 | # 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: |
97 | 97 | return self.name |
98 | 98 | else: |
99 | | return force_unicode(meta.verbose_name) |
| 99 | return force_unicode(model._meta.verbose_name) |
100 | 100 | |
101 | 101 | def model_class(self): |
102 | 102 | "Returns the Python model class for this type of content." |
=== modified file 'django/contrib/contenttypes/tests.py'
|
|
|
109 | 109 | obj = FooWithoutUrl.objects.create(name="john") |
110 | 110 | |
111 | 111 | 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') |