Skip to content
Advertisement

Group and Permissions Assignment Missing when using Custom User Model

I am building an app with multiple roles defined through Django Groups. I started with a custom user model, defined as below.

I am seeing a weird difference in the groups and permissions use when using a custom user model, like the inheritance is missing something.

I would like to use a custom user model so I don’t use username but I also need multiple groups and permissions in my application.

JavaScript

When I create a new group with the custom user model, the group gets automatically assigned to all created users. I reproduced this behavior both programmatically and through the Django Admin. When I use the default user model the group creation doesn’t assign groups to all users automatically. I also discovered that when using a custom user model the Django Admin for the users is not the same (the group and permission assignment fields are incomplete – screenshots below) Weird incomplete Django Admin interface with groups and permissions missing the available fields

Normal Django Admin interface with group and permission assignment as expected – default user model

Advertisement

Answer

I managed to fix the issue in the Admin panel. It seems that it’s a visual rendering problem caused by a wrong Admin class.

The error was caused by the following:

JavaScript

I have actually added the proper parameters in the class above but forgot to comment out/remove these lines. Works properly after commenting them out.

Advertisement