Search code examples
pythondjangodjango-allauthdjango-signals

django-allauth receiver signal to add group permission to user on signup


My goal is to add a new group to a user when they signup. I'm using the django-allauth package and it seems the best way to do this is to use the package defined signals. Not totally sure how to debug this as I have not been getting any error messages.

signals.py

from allauth.account.signals import user_signed_up
from django.dispatch import receiver
from django.contrib.auth.models import User
from django.contrib.auth.models import Group

#Group Added To New Users: "Can Add Pattern, Symbol, Broker"

@receiver(user_signed_up)
def user_signed_up_signal_handler(request, user):
    group = Group.objects.get(name='Can Add Pattern, Symbol, Broker')
    user.groups.add(group)
    user.save()

Solution

  • Not the fanciest answer but I was able to resolve this issue by putting the exact same code in my models.py file instead of signals.py.