Opened 12 years ago
Last modified 12 years ago
#20023 new Bug
Admin Inline form validation must go in Model.clean() if AdminInline.form is not specified
Reported by: | Owned by: | nobody | |
---|---|---|---|
Component: | Documentation | Version: | 1.5 |
Severity: | Normal | Keywords: | admin inline form validation |
Cc: | Triage Stage: | Accepted | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Pull Requests: | How to create a pull request | ||
Description ¶
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
According to the ticket's flags, the next step(s) to move this issue forward are:
- To provide a patch by sending a pull request. Claim the ticket when you start working so that someone else doesn't duplicate effort. Before sending a pull request, review your work against the patch review checklist. Check the "Has patch" flag on the ticket after sending a pull request and include a link to the pull request in the ticket comment when making that update. The usual format is:
[https://github.com/django/django/pull/#### PR]
.
Change History (3)
comment:1 by , 12 years ago
comment:2 by , 12 years ago
Summary: | Admin Inline form validation must go in Model.clean() → Admin Inline form validation must go in Model.clean() if AdminInline.form is not specified |
---|
comment:3 by , 12 years ago
Triage Stage: | Unreviewed → Accepted |
---|---|
Type: | Uncategorized → Bug |
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.