When you save the model form , the instance is saved first, then the save_m2m
method is called separately ( save_m2m
is called automatically if you do not save the form using commit=False
, in which case you must call it manually). You get the same result for both sets of queries, because much is saved for many fields later.
You can try using the m2m_changed
signal to track changes in the many to many field.
Original sentence (does not work):
Django requests are lazy . In this case, the first query is not evaluated until the model is saved, so it returns the same results as the second query.
You can force a query using list
.
differentiate_before_subscribed = list(Course.objects.get(id=self.id).subscribed.all())
source share