[Django] #20023: Admin Inline form validation must go in Model.clean()

8 views
Skip to first unread message

Django

unread,
Mar 11, 2013, 3:43:44 AM3/11/13
to django-...@googlegroups.com
#20023: Admin Inline form validation must go in Model.clean()
--------------------------------+------------------------------------------
Reporter: | Owner: nobody
chris.freeman.pdx@… | Status: new
Type: Uncategorized | Version: 1.5
Component: Documentation | Keywords: admin inline form validation
Severity: Normal | Has patch: 0
Triage Stage: Unreviewed | UI/UX: 0
Easy pickings: 0 |
--------------------------------+------------------------------------------
The Django admin site page (./en/1.5/ref/contrib/admin) should mention
something specific about inline form validation regarding where to put
clean() code.

It seems that the only way I was able to clean a field changed as part of
an admin inline form was in the Model.clean() method. I could not find a
place where using clean_myfield() method worked as all for admin inline
forms. Note the inline was not part of a formset, as it had a
OneToOneField relationship to the main form.

This is not obvious in the documentation as the Model page mentions
clean() and clean_field() but nothing about inlines. The documentation on
Inlines mentions validation, but nothing on putting the code in the
Model.clean(). Perhaps, also a warning that clean_field() is not run for
admin inline form updates.

Please correct me if I'm mistaken about validation of inline forms within
the Admin interface.

Regards, Chris

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

Django

unread,
Mar 12, 2013, 9:24:37 AM3/12/13
to django-...@googlegroups.com
#20023: Admin Inline form validation must go in Model.clean()
-------------------------------------+-------------------------------------
Reporter: chris.freeman.pdx@… | Owner: nobody
Type: Uncategorized | Status: new
Component: Documentation | Version: 1.5
Severity: Normal | Resolution:
Keywords: admin inline form | Triage Stage:
validation | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by chris.freeman.pdx@…):

* needs_better_patch: => 0
* needs_tests: => 0
* needs_docs: => 0


Comment:

I had a similar question open on StackOverflow
(http://stackoverflow.com/questions/15330490/django-clean-field-is-not-
being-called-for-updates-on-admin-inline-form). It was answered by
pointing to
(https://docs.djangoproject.com/en/dev/ref/contrib/admin/#django.contrib.admin.InlineModelAdmin.form),
which implies the answer: Since no form is specified, a model will be
used. However, if I specify the form, but ''not'' the model, I get a
{{{'model' is required attribute of 'ModelAdmin.inlines[0]'}}}.
Also, if form defaults to ModelForm, then it is not obvious that
ModelForm.clean_myfield() will not be called and only Model.clean() will
be called.

It would be much clearer if there were an Admin Inline example where both
AdminInline.model and AdminInline.form were defined for the same class.

The '''best''' solution would be to have a detailed example for the Admin
validation precedence (including Inlines) similar to what is described for
the model validation.

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

Django

unread,
Mar 12, 2013, 9:27:37 AM3/12/13
to django-...@googlegroups.com
#20023: Admin Inline form validation must go in Model.clean() if AdminInline.form
is not specified

-------------------------------------+-------------------------------------
Reporter: chris.freeman.pdx@… | Owner: nobody
Type: Uncategorized | Status: new
Component: Documentation | Version: 1.5
Severity: Normal | Resolution:
Keywords: admin inline form | Triage Stage:
validation | Unreviewed
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------

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

Django

unread,
Mar 13, 2013, 11:42:44 AM3/13/13
to django-...@googlegroups.com
#20023: Admin Inline form validation must go in Model.clean() if AdminInline.form
is not specified
-------------------------------------+-------------------------------------
Reporter: chris.freeman.pdx@… | Owner: nobody
Type: Bug | Status: new

Component: Documentation | Version: 1.5
Severity: Normal | Resolution:
Keywords: admin inline form | Triage Stage: Accepted
validation | Needs documentation: 0
Has patch: 0 | Patch needs improvement: 0
Needs tests: 0 | UI/UX: 0
Easy pickings: 0 |
-------------------------------------+-------------------------------------
Changes (by jacob):

* type: Uncategorized => Bug
* stage: Unreviewed => Accepted


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

Django

unread,
12:51 PM (3 hours ago) 12:51 PM
to django-...@googlegroups.com
#20023: Admin Inline form validation must go in Model.clean() if AdminInline.form
is not specified
-------------------------------------+-------------------------------------
Reporter: chris.freeman.pdx@… | Owner: Joseano
| Sousa
Type: Bug | Status: assigned
Component: Documentation | Version: 1.5
Severity: Normal | Resolution:
Keywords: admin inline form | Triage Stage: Accepted
validation |
Has patch: 0 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Joseano Sousa):

* owner: nobody => Joseano Sousa
* status: new => assigned

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

Django

unread,
12:52 PM (3 hours ago) 12:52 PM
to django-...@googlegroups.com
#20023: Admin Inline form validation must go in Model.clean() if AdminInline.form
is not specified
-------------------------------------+-------------------------------------
Reporter: chris.freeman.pdx@… | Owner: Joseano
| Sousa
Type: Bug | Status: assigned
Component: Documentation | Version: 1.5
Severity: Normal | Resolution:
Keywords: admin inline form | Triage Stage: Accepted
validation |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Changes (by Joseano Sousa):

* has_patch: 0 => 1

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

Django

unread,
1:01 PM (3 hours ago) 1:01 PM
to django-...@googlegroups.com
#20023: Admin Inline form validation must go in Model.clean() if AdminInline.form
is not specified
-------------------------------------+-------------------------------------
Reporter: chris.freeman.pdx@… | Owner: Joseano
| Sousa
Type: Bug | Status: assigned
Component: Documentation | Version: 1.5
Severity: Normal | Resolution:
Keywords: admin inline form | Triage Stage: Accepted
validation |
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
-------------------------------------+-------------------------------------
Comment (by Joseano Sousa):

Pull request: https://github.com/django/django/pull/21608
--
Ticket URL: <https://code.djangoproject.com/ticket/20023#comment:6>
Reply all
Reply to author
Forward
0 new messages