Opened 6 years ago
Closed 6 years ago
#29741 closed Cleanup/optimization (invalid)
There is no way to validate a ModelAdmin against it's inline formsets
Reported by: | Kyle Agronick | Owned by: | nobody |
---|---|---|---|
Component: | contrib.admin | Version: | 2.1 |
Severity: | Normal | Keywords: | validation forms admin |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | no | UI/UX: | no |
Description
If you wanted to do some validation that included taking data from the ModelAdmin's form and it's formsets there is currently no way to do that. If you wanted to check that the user did not duplicate values in the form and the formset you must override the entire _changeform_view method. (Over 100 lines) The form and the formset's clean() methods get called separately with no context of the overall page.
There is the save_related(request, form, formsets, change) method where you can do this kind of validation. You can add errors at this point but they will never be checked.
There should be some kind of process_related() method where you have the request, the form, and all of it's formsets in one context.
The exact problem I'm having is I have users entering a hostname record in the ModelAdmin's form and CNAME records for that hostname on the inline forms. There is no way to check that the user didn't put the same data in the main form and the formsets.
Change History (2)
comment:2 by , 6 years ago
Resolution: | → invalid |
---|---|
Status: | new → closed |
I'm going to close this, assuming you can validate as suggested. If not, please come back with more detail and we can re-open.
The inline's FormSet is given the parent object instance (already updated by saved if the parent form was valid) so can you not leverage that to validate against?
See Overriding Methods on an InlineFormSet. Can you not implement
clean()
accessing the parent object asself.instance
?