[Django]-Add user to group automatically after registration in Wagtail

3👍

Instead of using Django signals, Wagtail has hooks that simplify this for you. You can also send password reset email etc… after creating user using the same technique.

Just create a wagtail_hooks.py in your app:

from django.contrib.auth.models import Group
from wagtail.core import hooks
    
@hooks.register('after_create_user')
def add_user_to_group(request, user):
    if user:
       group, created = Group.objects.get_or_create(name='Group Name')
       user.groups.add(group)

Docs: https://docs.wagtail.io/en/latest/reference/hooks.html?highlight=after_create_user#id40

👤Mon

Leave a comment