Search code examples
pythondjangodjango-modelsdjango-registrationdjango-authopenid

How do I set a default group with django-authopenid?


I have a django app that uses django-authopenid as the sole registration method. I have registration in my installed apps, which django-authopenid uses. An ideal solution would allow me to run arbitrary code on the user object when they register. I can't directly modify the code for django-authopenis or registration.

Let me know if I need to add any more details.


Solution

  • On models.py you could bind the post_save signal:

    from django.contrib.auth.models import User, Group
    from django.db.models.signals import post_save
    
    
    def default_group(sender, instance, created, **kwargs):
        if created:
            instance.groups.add(Group.objects.get(name='your default group name'))
    post_save.connect(default_group, sender=User)
    

    If in doubt, read the signals documentation.