我在 Django 管理员中收到这些错误,任何人都可以帮助我吗
I am getting theses errors in Django admin can any one help me this
我是 Django 的新手,我正在尝试通过 运行 服务器为我的项目进行自定义身份验证我收到这些错误请帮助我解决这个问题。
ERRORS:
<class 'users.admin.UserAdmin'>: (admin.E008) The value of 'fieldsets[1][1]['fields']' must be a list or tuple.
<class 'users.admin.UserAdmin'>: (admin.E033) The value of 'ordering[1]' refers to 'name', which is not an attribute of 'users.user'.
<class 'users.admin.UserAdmin'>: (admin.E108) The value of 'list_display[0]' refers to 'name', which is not a callable, an attribute of 'UserAdmin', or an attribute or method on 'users.user'.
我的管理员密码是:
from __future__ import unicode_literals
from django.contrib.auth import get_user_model
from django.contrib import admin
User=get_user_model()
from django.contrib.auth.models import Group
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
from .forms import UserAdminCreationForm, UserAdminChangeForm
# Register your models here.
class UserAdmin(BaseUserAdmin):
form = UserAdminChangeForm
add_form = UserAdminCreationForm
list_display = ('name', 'phone', 'admin')
list_filter = ('staff','active','admin')
fieldsets = (
(None, {'fields':('phone', 'password')}),
('Personal info',{'fields':('name')}),
('Permissions', {'fields':('admin','staff','active')}),
)
add_fieldsets = (
(None, {
'classes': ('wide'),
'fileds': ('phone', 'password1', 'password2',),}
),
)
search_fields = ('phone','name')
ordering = ('phone','name')
filter_horizontal = ()
def get_inline_instances(self, request, obj=None):
if not obj:
return list()
return super(UserAdmin,self).get_inline_instances(request, obj)
admin.site.register(User,UserAdmin)
admin.site.unregister(Group)
错误消息都非常清楚和解释清楚,并告诉您确切的操作。
fieldsets[1][1]['fields']
设置为 ('name')
。这不是列表或元组,它只是带括号的字符串 'name'
。要使它成为一个元组,它应该是 ('name',)
,注意逗号。
ordering[1]
是 'name'
,它不是模型上的字段。去看看模型并选择一个字段。您是指 'username'
还是 'first_name'
?
list_display[0]
又是 'name'
,这又不是模型上的字段。也许你的意思是 'username'
?
看来您确实没有阅读错误消息,或者对 Python 的了解不够,无法理解您使用的代码,或者还没有完成 tutorial or read the admin docs,所以我建议稍作休息,通读这些内容并复习 Python 以及如何调试错误消息。
我是 Django 的新手,我正在尝试通过 运行 服务器为我的项目进行自定义身份验证我收到这些错误请帮助我解决这个问题。
ERRORS:
<class 'users.admin.UserAdmin'>: (admin.E008) The value of 'fieldsets[1][1]['fields']' must be a list or tuple.
<class 'users.admin.UserAdmin'>: (admin.E033) The value of 'ordering[1]' refers to 'name', which is not an attribute of 'users.user'.
<class 'users.admin.UserAdmin'>: (admin.E108) The value of 'list_display[0]' refers to 'name', which is not a callable, an attribute of 'UserAdmin', or an attribute or method on 'users.user'.
我的管理员密码是:
from __future__ import unicode_literals
from django.contrib.auth import get_user_model
from django.contrib import admin
User=get_user_model()
from django.contrib.auth.models import Group
from django.contrib.auth.admin import UserAdmin as BaseUserAdmin
from .forms import UserAdminCreationForm, UserAdminChangeForm
# Register your models here.
class UserAdmin(BaseUserAdmin):
form = UserAdminChangeForm
add_form = UserAdminCreationForm
list_display = ('name', 'phone', 'admin')
list_filter = ('staff','active','admin')
fieldsets = (
(None, {'fields':('phone', 'password')}),
('Personal info',{'fields':('name')}),
('Permissions', {'fields':('admin','staff','active')}),
)
add_fieldsets = (
(None, {
'classes': ('wide'),
'fileds': ('phone', 'password1', 'password2',),}
),
)
search_fields = ('phone','name')
ordering = ('phone','name')
filter_horizontal = ()
def get_inline_instances(self, request, obj=None):
if not obj:
return list()
return super(UserAdmin,self).get_inline_instances(request, obj)
admin.site.register(User,UserAdmin)
admin.site.unregister(Group)
错误消息都非常清楚和解释清楚,并告诉您确切的操作。
fieldsets[1][1]['fields']
设置为 ('name')
。这不是列表或元组,它只是带括号的字符串 'name'
。要使它成为一个元组,它应该是 ('name',)
,注意逗号。
ordering[1]
是 'name'
,它不是模型上的字段。去看看模型并选择一个字段。您是指 'username'
还是 'first_name'
?
list_display[0]
又是 'name'
,这又不是模型上的字段。也许你的意思是 'username'
?
看来您确实没有阅读错误消息,或者对 Python 的了解不够,无法理解您使用的代码,或者还没有完成 tutorial or read the admin docs,所以我建议稍作休息,通读这些内容并复习 Python 以及如何调试错误消息。