[Answered ]-Django multiple user with multiple groups problem at signup

1👍

This issue is caused because the signal sender is the User model itself. So saving the user instance of one of the profiles will call both the professeur_profil and etudiant_profil receivers. One approach to fix this is to change the senders of the receivers to the profile model instead:

@receiver(post_save, sender=Professeur)
def professeur_profil(sender, instance, created, **kwargs):
    if created:
        group = Group.objects.get(name='prof')
        instance.user.groups.add(group)


@receiver(post_save, sender=Etudiant)
def etudiant_profil(sender, instance, created, **kwargs):
    if created:
        group = Group.objects.get(name='etudiant')
        instance.user.groups.add(group)

Leave a comment