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
intermediatemodel for your M2M relationship and provide it with a custommanagerin which you can replace thecreatemethod.2) In my opinion though, the best way is to have on one of these models an instance method
add_somethingwhich provides the necessary validation and exception-handling logic.