how to set default user group in django

In your Django project, open the models.py file of the app that contains your user model.

from django.contrib.auth.models import Group

Then, create a function to assign the default group to a new user whenever a new user is created. Add this function to the signals in your models.py file.

@receiver(post_save, sender=User) def assign_default_group(sender, instance, created, kwargs): if created: group = Group.objects.get(name='your_group_name') instance.groups.add(group)

After that, import the necessary modules to link the above function to the post_save signal.

from django.db.models.signals import post_save from django.dispatch import receiver from django.contrib.auth.models import User