从 Django 1.11 迁移到 2.1:'fieldsets[2][1]' 中有重复字段

Migrating from Django 1.11 to 2.1: There are duplicate field(s) in 'fieldsets[2][1]'

我目前正在将我的 Django 1.11 应用程序迁移到 Django 2.1。我有一个自定义用户模型:

from authtools.models import AbstractEmailUser, UserManager
from django.db import models
from django.utils.translation import ugettext_lazy as _
from model_utils.fields import AutoLastModifiedField
from model_utils.models import SoftDeletableModel

from core.behaviors import UniversallyUniqueIdentifiable


class User(
    UniversallyUniqueIdentifiable,
    SoftDeletableModel,
    AbstractEmailUser
):
    """
    User should generally not be deleted, but rather is_removed should just
    be set to true. The delete() method is overwritten in the
    SoftDeletableModel.
    Also add a uuid field to avoid displaying the sequential primary key.
    """

    name = models.CharField(_('name'), max_length=255, blank=True)
    modified = AutoLastModifiedField(_('modified'))

    objects = UserManager()

还有一个自定义管理员:

from authtools.admin import (BASE_FIELDS, SIMPLE_PERMISSION_FIELDS,
                             NamedUserAdmin)
from django.contrib import admin

from .models import User


def verified(obj):
    email = obj.emailaddress_set.filter(primary=True)
    if email.exists():
        return email[0].verified
    return False


verified.boolean = True


@admin.register(User)
class SoftDeletableNamedUserAdmin(NamedUserAdmin):
    """
    Overwrite the fields of the NamedUserAdmin to add is_removed.
    """

    date_hierarchy = "date_joined"
    list_display = (
        'email',
        'name',
        verified,
        'is_active',
        'is_removed',
    )
    search_fields = ["email", "name"]
    readonly_fields = ("date_joined", "modified")
    fieldsets = (
        BASE_FIELDS,
        SIMPLE_PERMISSION_FIELDS,
        ("Contact information", {
            "fields": (
                ("email", "name"),
            )
        }),
        ("Account information", {
            "fields": (
                "is_removed",
            ),
        }),
        ("Dates", {
            "fields": (
                ("date_joined", "modified",),
            ),
        })
    )
    list_filter = ('is_active', 'is_removed',)

现在的问题是,当我启动服务器时,出现以下错误:

django.core.management.base.SystemCheckError: SystemCheckError: System check identified some issues:

ERRORS:
<class 'accounts.admin.SoftDeletableNamedUserAdmin'>: (admin.E012) There are duplicate field(s) in 'fieldsets[2][1]'.
<class 'accounts.admin.SoftDeletableNamedUserAdmin'>: (admin.E012) There are duplicate field(s) in 'fieldsets[3][1]'.
<class 'accounts.admin.SoftDeletableNamedUserAdmin'>: (admin.E012) There are duplicate field(s) in 'fieldsets[4][1]'.

我查看了 the documentation 以查看这些元组的定义方式是否发生了变化,但我没有发现任何差异。这里出了什么问题?

Print/log fieldsets 并删除所有重复项。例如,看起来 email 可能会明确包含在 BASE_FIELDS.

看起来检查不像以前版本的 Django 那样严格。此问题已在 Django 2.1 中由 ticket 29322 修复。