You can do this in several ways.
You can do this first as part of saving the model ()
In your model, do something like this:
def save(self):
if self.tags.count() > 3:
else:
super(MODEL_NAME,self).save()
Or you can do it manually in the view.
def some_view(request):
the_model = form.save(commit=False)
if the_model.tags.count() > 3:
else:
the_model.save()
Brant source
share