summaryrefslogtreecommitdiff
path: root/django
diff options
context:
space:
mode:
authorAnssi Kääriäinen <akaariai@gmail.com>2012-06-09 01:12:14 +0300
committerAnssi Kääriäinen <akaariai@gmail.com>2012-06-09 01:12:14 +0300
commit484fcd34a4819ff11ef72f3c9e1eb467a282b2f6 (patch)
treea2b48b8b65772b076068a1edaff5719a285962e7 /django
parenta035d9d6502c824155783dd74f88912ba2dffd9b (diff)
Fixed #16418 -- Made generic views work with ModelForms
Generic views assumed any object's _meta will be model Options. This is not true for ModelForms for example. Took isinstance(obj, Model) in use instead.
Diffstat (limited to 'django')
-rw-r--r--django/views/generic/detail.py7
1 files changed, 4 insertions, 3 deletions
diff --git a/django/views/generic/detail.py b/django/views/generic/detail.py
index 8cc413aa65..a5ddb5fe3e 100644
--- a/django/views/generic/detail.py
+++ b/django/views/generic/detail.py
@@ -1,6 +1,7 @@
from __future__ import unicode_literals
from django.core.exceptions import ImproperlyConfigured, ObjectDoesNotExist
+from django.db import models
from django.http import Http404
from django.utils.translation import ugettext as _
from django.views.generic.base import TemplateResponseMixin, ContextMixin, View
@@ -81,7 +82,7 @@ class SingleObjectMixin(ContextMixin):
"""
if self.context_object_name:
return self.context_object_name
- elif hasattr(obj, '_meta'):
+ elif isinstance(obj, models.Model):
return obj._meta.object_name.lower()
else:
return None
@@ -128,13 +129,13 @@ class SingleObjectTemplateResponseMixin(TemplateResponseMixin):
# The least-specific option is the default <app>/<model>_detail.html;
# only use this if the object in question is a model.
- if hasattr(self.object, '_meta'):
+ if isinstance(self.object, models.Model):
names.append("%s/%s%s.html" % (
self.object._meta.app_label,
self.object._meta.object_name.lower(),
self.template_name_suffix
))
- elif hasattr(self, 'model') and hasattr(self.model, '_meta'):
+ elif hasattr(self, 'model') and self.model is not None and issubclass(self.model, models.Model):
names.append("%s/%s%s.html" % (
self.model._meta.app_label,
self.model._meta.object_name.lower(),