【发布时间】:2020-02-27 02:11:39
【问题描述】:
我在我的项目中途创建了一个自定义用户,称为 OUser,在一个名为 accounts 的应用程序中。我在默认 AuthUserGroups 中定义了一些现有组。如何将 OUser 添加到组?当我尝试时,我得到一个错误,Invalid column name 'ouser_id'。我需要做什么才能允许将 OUser 添加到我的预定义组中?我是否必须创建自定义组模型来放置我的 OUser?无论如何我可以告诉 Auth_User_groups 它应该寻找 OUsers 吗?
accounts.admin
class OUserAdmin(BaseUserAdmin):
# The forms to add and change user instances
form = UserAdminChangeForm
add_form = UserAdminCreationForm
# The fields to be used in displaying the User model.
# These override the definitions on the base UserAdmin
# that reference specific fields on auth.User.
fieldsets = (
('Personal info', {'fields': ('first_name', 'last_name', 'email',)}),
('Permissions', {'fields': ('is_superuser', 'is_active', 'is_staff',)}),
)
# add_fieldsets is not a standard ModelAdmin attribute. UserAdmin
# overrides get_fieldsets to use this attribute when creating a user.
add_fieldsets = (
(None, {
'classes': ('wide',),
'fields': ('username',)}
),
)
search_fields = ('username',)
ordering = ('username',)
filter_horizontal = ()
list_filter = ('is_superuser',)
admin.site.register(OUser, OUserAdmin)
'''
There are also other dependencies on things, such as Auth_Group_permission, but I assume that it will be a similar fix to switching Auth_Group to using OUser.
How would I make groups contain references to Ouser. I have tried just swapping the Foreign key of the user_id in AuthUserGroups to contain a reference to OUser, but that didn't work. Maybe I missed something?
Thanks for the help!
【问题讨论】:
标签: django-models django-admin django-authentication