6

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

1 Answers1

16

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.

MPatel1
  • 181
  • 2
  • 10
Del
  • 544
  • 6
  • 18
  • 3
    Thank you. This answer was helpful. Just I want to add one more in here for newbie. If you inherit PermissionsMixin after you already have done migration and migrate with your custom user model, It doesn't create relationship between your custom user model and group or permissions. I was confused for awhile because after inheriting PermissionMixin, I couldn't find tables in db for relationship between user and Group or user and Permission. – Jayground Nov 15 '16 at 07:01
  • Did you register Group model through `admin.site.register(Group)` ? – Yasser Mohsen Jun 05 '20 at 10:55