[Django]-Django – clean_field() is not being called for updates on admin inline form

10👍

Validation occurs on ModelForm objects, not ModelAdmin objects. If you want to override any clean methods then you have to create your own ModelForm descendent for each required model.

In your example, the PrimaryInline class does not specify a form. If not specified, the form used will be a ModelForm, which doesn’t have any of your custom clean methods.

Try this:

class PrimaryInline(admin.StackedInline):
    # ... existing code ...
    form = PrimaryAdminForm

This will now use your custom PrimaryAdminForm with associated clean() methods.

Leave a comment