Skip to content Skip to sidebar Skip to footer

Modified Django Admin Clean() Method Not Being Invoked

I have developed a tool (to be used internally) based on the Django admin site. I have model validators in place which work brilliantly, but to do more complex validations, I am at

Solution 1:

You have created a model form, but you have not told Django to use it.

You should create a model admin, and set form to your model form:

class ProviderAdmin(admin.ModelAdmin):
    form = ProviderForm

Then register your model with your model admin class:

admin.site.register(Provider, ProviderAdmin)

Solution 2:

You should call the super() int the clean method:

def clean(self):

    cleaned_data = super(ProviderForm, self).clean()

EDIT:

This is not the correct answer, @Alasdair above is. As pointed by @scharette in the comments

This is relevant only if your form inherits another that doesn’t return a cleaned_data dictionary in its clean() method. Also, if you're using python 3 there is no need to have parameters


Solution 3:

Considering your indentation is only an issue of posting your code, my guess is you forgot to override the admin class. Here is what you need to do:

class ProviderAdmin(admin.ModelAdmin):
    form = ProviderForm


admin.site.register(Provider,ProviderAdmin)

You were on the right path you just forgot to register an override on the admin class by specifying the form with clean override


Post a Comment for "Modified Django Admin Clean() Method Not Being Invoked"