m2m_changed signal | Multiple m2m fields - fields' value overriding | DRF

90 views
Skip to first unread message

Vibhu Agarwal

unread,
Nov 17, 2020, 11:26:44 AM11/17/20
to Django users
Here's the task I'm trying to do:
m2m_changed.png
Full Code: test_django_project/m2m_change_triggers/models.py

Here's the issue: 2nd test in test_django_project/m2m_change_triggers/tests.py fails, but 1st one passes!

Did some digging and found that issue is probably here: rest_framework/serializers.py#L988-L990
The signal is called in both the tests, but `users` field modified by the signal is getting overriden by `field.set(value)` in `ModelSerializer` `save()`

- How do I solve the issue (both the tests should pass)?
- Is using signals the best approach here? Do I have an alternative?

How I've implemented the feature temporarily: using the same thing at the view-level, and not at the model-level.
Reply all
Reply to author
Forward
0 new messages