问题
When editing user model through admin interface, here's what I see: And here's what I expect to see: The second one allows me to modify the user permissions, the first one does not.
The User model I use on the first screenshot inherits from AbstractUser
and is registered in the following way:
from django.contrib import admin
import accounts.models
admin.site.register(accounts.models.User)
In my settings:
DEBUG = True
AUTH_USER_MODEL = 'accounts.User'
What can be the problem? How do I get from the first screenshot to the second?
回答1:
Had the same issue but the solution is quite simple. In your admin.py file just add 'groups', 'user_permissions' to filter_horizontal = () i.e
filter_horizontal = ('groups', 'user_permissions')
that is basically it.
referenced from: https://djangobook.com/customizing-change-lists-forms/
回答2:
OK, the actual problem was that I inherited not from AbstractUser
but from AbstractBaseUser
and forgot about PermissionsMixin
(the mixin adds the apropriate fields). So I should've done something like this.
来源:https://stackoverflow.com/questions/45837617/django-admin-wont-allow-me-to-modify-user-permissions-and-groups