First, you’d be better off doing this work in form_valid
rather than get_success_url
.
You should also have your clean function for “when” in the form and not perform any additional validation in the view. The form_valid
method should only be called once the entire form has been verified correct.
You can call super
in your form_valid
method and save the return value in a variable, update the objects, then return that saved value from your form_valid
method.
See the docs and examples at Many-to-many relationships | Django documentation | Django for working with ManyToManyFields.