Opened 7 years ago
Last modified 17 months ago
#26220 new New feature
Allow SingleObjectTemplateResponseMixin to get a template_name from form_class if it's a ModelForm
Reported by: | Guilhem Saurel | Owned by: | |
---|---|---|---|
Component: | Generic views | Version: | 1.9 |
Severity: | Normal | Keywords: | |
Cc: | berker.peksag@… | Triage Stage: | Accepted |
Has patch: | yes | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | yes |
Easy pickings: | no | UI/UX: | no |
Description
In this case, we have to set twice the model (or manually set template_name):
class ArticleForm(ModelForm): class Meta: model = Article fields = ['author', 'date'] def clean_date(self): ... class ArticleCreateView(CreateView): form_class = ArticleForm model = Article # Redundant
A PoC to fix this is available here: https://github.com/nim65s/django/commit/614dae5022bb5c7d8ad0336e17ef1e0c84b9dbbf
Change History (8)
comment:1 Changed 7 years ago by
Has patch: | set |
---|---|
Needs tests: | set |
Summary: | CBV: Finding template_name from form_class if it's a ModelForm → Allow SingleObjectTemplateResponseMixin to get a template_name from form_class if it's a ModelForm |
Triage Stage: | Unreviewed → Accepted |
comment:2 follow-up: 3 Changed 7 years ago by
Cc: | berker.peksag@… added |
---|
comment:3 Changed 7 years ago by
Replying to berkerpeksag:
Should we also make
model
optional forUpdateView
andDeleteView
?
What do you mean ? Is there any code that prevents you not to add a model
on an UpdateView
or a DeleteView
?
In my case, I tested my PoC without any model
and it worked… So it is optionnal, isn't it ?
comment:4 Changed 7 years ago by
So I've checked tests. SingleObjectMixin.get_queryset
needed the same kind of modification.
Here is the updated commit:
https://github.com/nim65s/django/commit/3fca6100e573315169281ad15a513e8841791bfc
Tests are passing and coverage is green on my modifications.
comment:5 Changed 7 years ago by
Could you please create a patch following our PatchReviewChecklist and send a pull request against master?
comment:6 Changed 7 years ago by
Owner: | changed from nobody to Guilhem Saurel |
---|---|
Status: | new → assigned |
Here it is: https://github.com/django/django/pull/6311
comment:7 Changed 7 years ago by
Needs tests: | unset |
---|---|
Patch needs improvement: | set |
Left a few comments for improvement. Please uncheck "Patch needs improvement" after you update it. Thanks!
comment:8 Changed 17 months ago by
Owner: | Guilhem Saurel deleted |
---|---|
Status: | assigned → new |
Should we also make
model
optional forUpdateView
andDeleteView
?