Opened 9 years ago

Last modified 8 days ago

#26220 assigned New feature

Allow SingleObjectTemplateResponseMixin to get a template_name from form_class if it's a ModelForm

Reported by: Guilhem Saurel Owned by: Clifford Gama
Component: Generic views Version: 1.9
Severity: Normal Keywords:
Cc: berker.peksag@…, Clifford Gama Triage Stage: Accepted
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
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 (13)

comment:1 by Tim Graham, 9 years ago

Has patch: set
Needs tests: set
Summary: CBV: Finding template_name from form_class if it's a ModelFormAllow SingleObjectTemplateResponseMixin to get a template_name from form_class if it's a ModelForm
Triage Stage: UnreviewedAccepted

comment:2 by Berker Peksag, 9 years ago

Cc: berker.peksag@… added

Should we also make model optional for UpdateView and DeleteView?

in reply to:  2 comment:3 by Guilhem Saurel, 9 years ago

Replying to berkerpeksag:

Should we also make model optional for UpdateView and DeleteView?

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 by Guilhem Saurel, 9 years ago

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/91f221b9e1d221d0f56213e187fcdf8e7564ded7

Tests are passing and coverage is green on my modifications.

Last edited 9 years ago by Guilhem Saurel (previous) (diff)

comment:5 by Tim Graham, 9 years ago

Could you please create a patch following our PatchReviewChecklist and send a pull request against master?

comment:6 by Guilhem Saurel, 9 years ago

Owner: changed from nobody to Guilhem Saurel
Status: newassigned

comment:7 by Tim Graham, 9 years ago

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 by Mariusz Felisiak, 3 years ago

Owner: Guilhem Saurel removed
Status: assignednew

comment:9 by Clifford Gama, 5 weeks ago

Cc: Clifford Gama added

comment:10 by Clifford Gama, 3 weeks ago

Owner: set to Clifford Gama
Status: newassigned

comment:11 by Clifford Gama, 2 weeks ago

Patch needs improvement: unset

comment:12 by Clifford Gama, 2 weeks ago

Patch needs improvement: set

comment:13 by Clifford Gama, 8 days ago

Patch needs improvement: unset
Note: See TracTickets for help on using tickets.
Back to Top