I would like to change the behavior, maybe overwriting, when I add an instance to a M2M relation, so that I could do something like this:
try:
my_instance.one_field_set.add( another_instance )
except ValidationError:
# do something
Is that possible?
Yes but don't do it that way.
1) Use can use an explicit
intermediate
model for your M2M relationship and provide it with a custommanager
in which you can replace thecreate
method.2) In my opinion though, the best way is to have on one of these models an instance method
add_something
which provides the necessary validation and exception-handling logic.