[Django] #26220: CBV: Finding template_name from form_class if it's a ModelForm

8 views
Skip to first unread message

Django

unread,
Feb 14, 2016, 3:36:26 PM2/14/16
to django-...@googlegroups.com
#26220: CBV: Finding template_name from form_class if it's a ModelForm
-------------------------------+--------------------
Reporter: nim65s | Owner: nobody
Type: New feature | Status: new
Component: Generic views | Version: 1.9
Severity: Normal | Keywords:
Triage Stage: Unreviewed | Has patch: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------+--------------------
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

--
Ticket URL: <https://code.djangoproject.com/ticket/26220>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

Django

unread,
Feb 15, 2016, 12:58:54 PM2/15/16
to django-...@googlegroups.com
#26220: Allow SingleObjectTemplateResponseMixin to get a template_name from

form_class if it's a ModelForm
-------------------------------+------------------------------------

Reporter: nim65s | Owner: nobody
Type: New feature | Status: new
Component: Generic views | Version: 1.9
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------
Changes (by timgraham):

* needs_better_patch: => 0
* needs_tests: => 1
* needs_docs: => 0
* has_patch: 0 => 1
* stage: Unreviewed => Accepted


--
Ticket URL: <https://code.djangoproject.com/ticket/26220#comment:1>

Django

unread,
Feb 22, 2016, 6:00:56 PM2/22/16
to django-...@googlegroups.com
#26220: Allow SingleObjectTemplateResponseMixin to get a template_name from

form_class if it's a ModelForm
-------------------------------+------------------------------------

Reporter: nim65s | Owner: nobody
Type: New feature | Status: new
Component: Generic views | Version: 1.9
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------
Changes (by berkerpeksag):

* cc: berker.peksag@… (added)


Comment:

Should we also make `model` optional for `UpdateView` and `DeleteView`?

--
Ticket URL: <https://code.djangoproject.com/ticket/26220#comment:2>

Django

unread,
Mar 1, 2016, 3:37:42 PM3/1/16
to django-...@googlegroups.com
#26220: Allow SingleObjectTemplateResponseMixin to get a template_name from

form_class if it's a ModelForm
-------------------------------+------------------------------------

Reporter: nim65s | Owner: nobody
Type: New feature | Status: new
Component: Generic views | Version: 1.9
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------

Comment (by Nim65s):

Replying to [comment:2 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 ?

--
Ticket URL: <https://code.djangoproject.com/ticket/26220#comment:3>

Django

unread,
Mar 1, 2016, 6:01:15 PM3/1/16
to django-...@googlegroups.com
#26220: Allow SingleObjectTemplateResponseMixin to get a template_name from

form_class if it's a ModelForm
-------------------------------+------------------------------------

Reporter: nim65s | Owner: nobody
Type: New feature | Status: new
Component: Generic views | Version: 1.9
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------

Comment (by Nim65s):

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.

--
Ticket URL: <https://code.djangoproject.com/ticket/26220#comment:4>

Django

unread,
Mar 2, 2016, 7:57:26 AM3/2/16
to django-...@googlegroups.com
#26220: Allow SingleObjectTemplateResponseMixin to get a template_name from

form_class if it's a ModelForm
-------------------------------+------------------------------------

Reporter: nim65s | Owner: nobody
Type: New feature | Status: new
Component: Generic views | Version: 1.9
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------

Comment (by timgraham):

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

--
Ticket URL: <https://code.djangoproject.com/ticket/26220#comment:5>

Django

unread,
Mar 19, 2016, 9:06:23 AM3/19/16
to django-...@googlegroups.com
#26220: Allow SingleObjectTemplateResponseMixin to get a template_name from

form_class if it's a ModelForm
-------------------------------+------------------------------------
Reporter: nim65s | Owner: nim65s
Type: New feature | Status: assigned

Component: Generic views | Version: 1.9
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 1 | Patch needs improvement: 0

Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------
Changes (by nim65s):

* status: new => assigned
* owner: nobody => nim65s


Comment:

Here it is: https://github.com/django/django/pull/6311

--
Ticket URL: <https://code.djangoproject.com/ticket/26220#comment:6>

Django

unread,
Mar 21, 2016, 2:02:03 PM3/21/16
to django-...@googlegroups.com
#26220: Allow SingleObjectTemplateResponseMixin to get a template_name from

form_class if it's a ModelForm
-------------------------------+------------------------------------
Reporter: nim65s | Owner: nim65s
Type: New feature | Status: assigned
Component: Generic views | Version: 1.9
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1

Easy pickings: 0 | UI/UX: 0
-------------------------------+------------------------------------
Changes (by timgraham):

* needs_better_patch: 0 => 1
* needs_tests: 1 => 0


Comment:

Left a few comments for improvement. Please uncheck "Patch needs
improvement" after you update it. Thanks!

--
Ticket URL: <https://code.djangoproject.com/ticket/26220#comment:7>

Django

unread,
Jan 14, 2022, 4:43:15 AM1/14/22
to django-...@googlegroups.com
#26220: Allow SingleObjectTemplateResponseMixin to get a template_name from

form_class if it's a ModelForm
--------------------------------+------------------------------------
Reporter: Guilhem Saurel | Owner: (none)

Type: New feature | Status: new
Component: Generic views | Version: 1.9
Severity: Normal | Resolution:
Keywords: | Triage Stage: Accepted
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 1
Easy pickings: 0 | UI/UX: 0
--------------------------------+------------------------------------
Changes (by Mariusz Felisiak):

* owner: Guilhem Saurel => (none)
* status: assigned => new


--
Ticket URL: <https://code.djangoproject.com/ticket/26220#comment:8>

Reply all
Reply to author
Forward
0 new messages