Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How add group for custom user in django?

I created custom model of user using this official docs customizing authentication in Django But how can add groups and premissions? My django is version 1.9

like image 275
Sergey Tytarenko Avatar asked Apr 30 '16 23:04

Sergey Tytarenko


People also ask

How do I categorize users in Django?

Groups: Way of Categorizing UsersDjango provides a basic view in the admin to create these groups and manage the permissions. The group denotes the “role” of the user in the system. As an “admin”, you may belong to a group called “admin”. As a “support staff”, you would belong to a group called “support”.

How do I add custom permissions to Django?

Django Admin Panel : In Admin Panel you will see Group in bold letter, Click on that and make 3-different group named level0, level1, level3 . Also, define the custom permissions according to the need. By Programmatically creating a group with permissions: Open python shell using python manage.py shell.


1 Answers

You can use groups and permissions with your custom user model by using the PermissionsMixin (https://docs.djangoproject.com/en/3.1/topics/auth/customizing/#custom-users-and-permissions)

Just inherit the PermissionsMixin with your custom user model like so:

class CustomUser(AbstractBaseUser, PermissionsMixin):

Then you can access it in exactly the same way you would with the default django.contrib.auth User model.

like image 98
Del Avatar answered Sep 24 '22 10:09

Del