Opened 16 months ago
Closed 16 months ago
#34774 closed New feature (duplicate)
ModelAdmin form validation that cross-validates main form and inline formsets
Reported by: | ldeluigi | Owned by: | nobody |
---|---|---|---|
Component: | contrib.admin | Version: | 4.2 |
Severity: | Normal | Keywords: | formsets crossvalidation inlines form admin modeladmin |
Cc: | Triage Stage: | Unreviewed | |
Has patch: | no | Needs documentation: | no |
Needs tests: | no | Patch needs improvement: | no |
Easy pickings: | yes | UI/UX: | no |
Description
I'd like to validate the admin change form submission for my entity together with its inline formsets.
In particular, I need to compute and validate a field based on the model relationships, that is its inlines that were submitted.
I can't use any of the forms clean()
method because they can't access other forms of the same submission, unless I'm parsing the request manually (duplicating the code from the inline formset arguments parser).
Proposal:
instead of calling the all_valid()
method directly from _changeform_view()
in the ModelAdmin implementation, you could first call an instance method like for example self.validate_formsets(form, formsets)
which returns True if all the forms are valid.
The default implementation in ModelAdmin would be:
def validate_formsets(self, form, formsets): form_validated = form.is_valid() return all_valid(formsets) and form_validated
then users can override it to customize the behavior, including cross-validating forms cleaned data.
Change History (2)
comment:1 by , 16 months ago
Summary: | Admin form validation that cross-validates main form and inline formsets → ModelAdmin form validation that cross-validates main form and inline formsets |
---|
comment:2 by , 16 months ago
Has patch: | unset |
---|---|
Resolution: | → duplicate |
Status: | new → closed |
Duplicate of #12780.