create django group
To create a Django group, follow these steps:
- First, import the necessary modules:
from django.contrib.auth.models import Group
- Then, create the group using the
Group.objects.create
method:
new_group, created = Group.objects.get_or_create(name='new_group_name')
- Next, assign permissions to the group using the
group.permissions.add
method:
new_group.permissions.add(permission1, permission2)
- Finally, save the group to apply the changes:
new_group.save()