diff --git a/django/views/generic/detail.py b/django/views/generic/detail.py
index 7e9047f..43ec36e 100644
a
|
b
|
class SingleObjectMixin(object):
|
58 | 58 | `get_object` is overridden. |
59 | 59 | """ |
60 | 60 | if self.queryset is None: |
61 | | if self.model: |
62 | | return self.model._default_manager.all() |
| 61 | model = self.get_model() |
| 62 | if model: |
| 63 | return model._default_manager.all() |
63 | 64 | else: |
64 | 65 | raise ImproperlyConfigured(u"%(cls)s is missing a queryset. Define " |
65 | 66 | u"%(cls)s.model, %(cls)s.queryset, or override " |
… |
… |
class SingleObjectMixin(object):
|
92 | 93 | context[context_object_name] = self.object |
93 | 94 | return context |
94 | 95 | |
| 96 | def get_model(self): |
| 97 | return self.model |
| 98 | |
95 | 99 | |
96 | 100 | class BaseDetailView(SingleObjectMixin, View): |
97 | 101 | def get(self, request, **kwargs): |
… |
… |
class SingleObjectTemplateResponseMixin(TemplateResponseMixin):
|
132 | 136 | self.object._meta.object_name.lower(), |
133 | 137 | self.template_name_suffix |
134 | 138 | )) |
135 | | elif hasattr(self, 'model') and hasattr(self.model, '_meta'): |
136 | | names.append("%s/%s%s.html" % ( |
137 | | self.model._meta.app_label, |
138 | | self.model._meta.object_name.lower(), |
139 | | self.template_name_suffix |
140 | | )) |
| 139 | elif hasattr(self, 'get_model'): |
| 140 | model = self.get_model() |
| 141 | if hasattr(model, '_meta'): |
| 142 | names.append("%s/%s%s.html" % ( |
| 143 | model._meta.app_label, |
| 144 | model._meta.object_name.lower(), |
| 145 | self.template_name_suffix |
| 146 | )) |
141 | 147 | return names |
142 | 148 | |
143 | 149 | |
diff --git a/django/views/generic/edit.py b/django/views/generic/edit.py
index 3cade52..fbe09b9 100644
a
|
b
|
class ModelFormMixin(FormMixin, SingleObjectMixin):
|
75 | 75 | if self.form_class: |
76 | 76 | return self.form_class |
77 | 77 | else: |
78 | | if self.model is not None: |
79 | | # If a model has been explicitly provided, use it |
80 | | model = self.model |
81 | | elif hasattr(self, 'object') and self.object is not None: |
82 | | # If this view is operating on a single object, use |
83 | | # the class of that object |
84 | | model = self.object.__class__ |
85 | | else: |
86 | | # Try to get a queryset and extract the model class |
87 | | # from that |
88 | | model = self.get_queryset().model |
| 78 | model = self.get_model() |
89 | 79 | return model_forms.modelform_factory(model) |
90 | 80 | |
91 | 81 | def get_form_kwargs(self): |
… |
… |
class ModelFormMixin(FormMixin, SingleObjectMixin):
|
120 | 110 | if context_object_name: |
121 | 111 | context[context_object_name] = self.object |
122 | 112 | return context |
| 113 | |
| 114 | def get_model(self): |
| 115 | if self.model: |
| 116 | return self.model |
| 117 | elif self.form_class and issubclass(self.form_class, model_forms.ModelForm): |
| 118 | return self.form_class._meta.model |
| 119 | elif hasattr(self, 'object') and self.object is not None: |
| 120 | return self.object.__class__ |
| 121 | else: |
| 122 | return self.get_queryset().model |
123 | 123 | |
124 | 124 | |
125 | 125 | class ProcessFormView(View): |