User Authentication

DJANGO


Manage user groups

Well a Group is just another model in Django (one of the models defined in the Django library).

You can thus create a group with:

from django.contrib.auth.models import Group

g1 = Group.objects.create(name='Name of the group')

The Group model has two many-to-many relations: one to Users (with related name users), and one to Permission (with related name permissions). So we can use the corresponding managers to add and remove Users and Permissions.

Then you can for example populate the group with users like:

g1.user_set.add(user1, user2, user5, user7)

You can also add permissions to a group with:

g1.permissions.add(perm1, perm3, perm4)

 

Extending User Model

https://simpleisbetterthancomplex.com/tutorial/2016/07/22/how-to-extend-django-user-model.html#disqus_thread

 

            Related
User Authentication