1๐
-
If you want to do some custom validation, youโd better do it via forms, or (as a last resort), using the
Model.clean*
methods family.class Campaign(models.Model): def clean(self): if self.pk: if self.item_set.count() > 5 # Or whatever number you need raise ValidationError(_('Too much items for me.'))
-
Override the
get_extra()
method for your inline:class ItemInline(admin.TabularInline): extra = 4 def get_extra(self, request, obj=None, **kwargs): if obj: return obj.rows * obj.columns return self.extra
๐คAlex Morozov
Source:stackexchange.com