{{{
class Game(models.Model):
participants = models.ManyToManyField(
to='card_users.UserProfile',
related_name='card_games',
through='cardgame.GameThroughModel',
)
class GameThroughModel(models.Model):
game = models.ForeignKey(
to='card_game.Game',
on_delete=models.CASCADE,
)
participant = models.ForeignKey(
to='card_users.UserProfile',
on_delete=models.CASCADE,
)
class UserProfile(models.Model):
user = models.OneToOneField(
to=settings.AUTH_USER_MODEL,
on_delete=models.CASCADE,
related_name='profile',
)
}}}
I have a receiver set up to perform further actions when new participants
are added using m2m_changed:
{{{
@receiver(m2m_changed, sender=Game.participants.through,
dispatch_uid='create_initial_round', weak=False)
def create_initial_round(sender, instance, action, **kwargs):
print(f"{sender}, {instance}, {action}")
}}}
The m2m_changed signal is not received. When a standard manytomany model
relation is used ie.:
{{{
class Game(models.Model):
participants = models.ManyToManyField(
to='card_users.UserProfile',
related_name='card_games',
)
}}}
the signal is received correctly.
--
Ticket URL: <https://code.djangoproject.com/ticket/32515>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.
* keywords: m2m_changed, signals => m2m_changed, signal, custom model,
--
Ticket URL: <https://code.djangoproject.com/ticket/32515#comment:1>
Comment (by leon hughes):
keyword changes
--
Ticket URL: <https://code.djangoproject.com/ticket/32515#comment:2>
* status: new => closed
* resolution: => invalid
Comment:
The `m2m_changed` signal was created for automatically created
intermediate models. If you have an explicit `through` model, you can
attached `Model` signals to it, i.e. `pre_save`, `post_save`,
`pre_delete`, and `post_delete`.
--
Ticket URL: <https://code.djangoproject.com/ticket/32515#comment:3>