【问题标题】:Django Admin error admin.E008 The value of fieldsets must be a list or tupleDjango Admin 错误 admin.E008 字段集的值必须是列表或元组
【发布时间】:2015-08-01 19:50:50
【问题描述】:

在为我创建的自定义用户编写自定义管理模型后出现此错误。这是用户管理员的代码:

class MyUserAdmin(UserAdmin):
    form = UserChangeForm
    add_form=UserCreationForm

    fieldsets = (
        ('Personal Details', {
           'fields': (
               'emp_id',
               ('emp_first_name', 'emp_last_name'),
               ('emp_gender', 'emp_dob', 'emp_marital_status'),
               ('emp_current_add','emp_permanent_add'), 
               ('emp_email_id', 'emp_mobile'),
               'emp_interests'
           )}),
        ('Company Details', {
            'fields': (
                'emp_designation',
                'emp_expertise', 
                ('emp_desk_ph', 'emp_pcname', 'emp_current_location'),
                ('emp_comp_join_date', 'emp_account_join_date'),             
                ('emp_farewell_date', 'emp_company_termination_date', 'emp_account_termination_date', 'emp_relocation_date'),
                'is_active'
            )}),
        ('Permission', {
            'fields': (
                ('is_superuser','is_staff','is_admin'),
                'groups'
            )}),
        ('Password Details',{'fields' : ('password')}),)

运行makemigrations 命令后,我得到这个错误:

SystemCheckError: System check identified some issues:

ERRORS: <class 'user.admin.MyUserAdmin'>: (admin.E008) 
The value of 'fieldsets[1]['fields']' must be a list or tuple.

【问题讨论】:

    标签: python django django-admin


    【解决方案1】:

    您的“密码详细信息”字段集中缺少尾随逗号。应该是:

    ('Password Details',{'fields' : ('password',)}),)
                                               ^
                                               | # this comma
    

    没有逗号,('password')'password' 一样,都是字符串,不是元组。

    【讨论】:

    • 错误信息有点误导。在这种情况下,它应该说The value of 'fieldsets[3][1]['fields'] must be a list or tuple。我已经打开a ticket 来修复错误消息。
    猜你喜欢
    • 2016-05-13
    • 2014-08-07
    • 2018-04-02
    • 2021-12-21
    • 2019-08-27
    • 1970-01-01
    • 2019-12-14
    • 2018-06-14
    • 2023-02-02
    相关资源
    最近更新 更多