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
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”.
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.
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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With