I have a model in which the is an option for setting if an element is active or not.
There is restriction to the number of elements that can have the "active" property with a "True" value.
I have writen validation code on the AdminModel. So now if when editing an elemnt i mark it as "active" and i have reach the limit of "actvie" elements, i raise an exception.
def clean_active(self):
if self.cleaned_data["active"]:
#check number of active elements in model.
In the admin interface i have also a list of objects. In this list i have marked as editable the field "active", list_display = ('name', 'first_promotion', 'second_promotion','active') readonly_fields= ['name'] list_editable= ['active']
What I want is to be able of also making this validation on the "list display" of the model. I'm not able where i should add the validation code for the list display.
Could anybody show me how to do this? Thanks in advance.
Good question! The changelist form appears to be pulled from
ModelAdmin.get_changelist_form
where you can supply your ownModelForm
to serve as the modelformset base model.If you want to modify the formsets validation (the collection of forms) you'd override
get_changelist_formset