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.