I have overridden my save() method on a model, in order to add some ManyToMany objects to it. If I call the super().save() method after I add the objects, I get the classic error that a model needs a PK before adding ManyToMany objects, which is normal. However If I call it both before and after, the objects simply don't get added.
My code looks like this:
def save(self, force_insert=False, force_update=False):
super(Teacher, self).save(force_insert, force_update)
from school.models import Course
disciplinary = Course.objects.filter(type=Course.TYPE_DISCIPLINARY)
for disc in disciplinary:
print disc # this gets called
self.subjects.add(disc)
super(Teacher, self).save(force_insert, force_update)
This produces no errors, but doesn't add the appropriate Courses.
save()on your model, then it will add the m2m objects that were submitted in the admin form... if this field was empty it will replace the objects you add in your overriddensavemethod with an empty set