diff -r 78e735c39934 django/views/generic/detail.py
a
|
b
|
|
139 | 139 | if name: |
140 | 140 | names.insert(0, name) |
141 | 141 | |
| 142 | def format_name(meta) : |
| 143 | return "%s/%s%s.html" % ( |
| 144 | meta.app_label, |
| 145 | meta.object_name.lower(), |
| 146 | self.template_name_suffix, |
| 147 | ) |
142 | 148 | # The least-specific option is the default <app>/<model>_detail.html; |
143 | 149 | # only use this if the object in question is a model. |
144 | 150 | if isinstance(self.object, models.Model): |
145 | | names.append("%s/%s%s.html" % ( |
146 | | self.object._meta.app_label, |
147 | | self.object._meta.object_name.lower(), |
148 | | self.template_name_suffix |
149 | | )) |
| 151 | names.append(format_name(self.object._meta)) |
150 | 152 | elif hasattr(self, 'model') and self.model is not None and issubclass(self.model, models.Model): |
151 | | names.append("%s/%s%s.html" % ( |
152 | | self.model._meta.app_label, |
153 | | self.model._meta.object_name.lower(), |
154 | | self.template_name_suffix |
155 | | )) |
| 153 | names.append(format_name(self.model._meta)) |
| 154 | elif hasattr(self, 'queryset') and self.queryset is not None and hasattr(self.queryset, 'model') : |
| 155 | names.append(format_name(self.queryset.model._meta)) |
| 156 | # Raise the exception early on because this method is not part of the |
| 157 | # traceback generated by the resulting exception in template/loader.py |
| 158 | # select_template method. If another way is supported in the future to |
| 159 | # specify the object we're operating on, the logic to obtain it's meta |
| 160 | # class should be added above this comment. |
| 161 | elif not names : |
| 162 | raise ImproperlyConfigured("No template name set and unable to generate candidates.") |
156 | 163 | return names |
157 | 164 | |
158 | 165 | |
diff -r 78e735c39934 tests/regressiontests/generic_views/edit.py
a
|
b
|
|
89 | 89 | self.assertRedirects(res, reverse('author_detail', kwargs={'pk': obj.pk})) |
90 | 90 | self.assertQuerysetEqual(Author.objects.all(), ['<Author: Randall Munroe>']) |
91 | 91 | |
| 92 | def test_create_form_using_queryset(self) : |
| 93 | res = self.client.get('/edit/authors/create/naive/') |
| 94 | self.assertEqual(res.status_code, 200) |
| 95 | self.assertTemplateUsed('generic_views/author_form.html') |
| 96 | |
92 | 97 | def test_create_without_redirect(self): |
93 | 98 | try: |
94 | 99 | res = self.client.post('/edit/authors/create/naive/', |