Django-admin won't allow me to modify user permissions and groups

孤街醉人 提交于 2021-01-28 05:22:52

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!