我目前正在将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,以查看这些元组的定义方式是否已更改,但我看不出有什么区别。怎么了?
答案 0 :(得分:1)
打印/记录fieldsets
并删除所有重复项。例如,看起来email
可能明确包含在BASE_FIELDS
中。
似乎检查没有像以前的Django版本那样严格。这是由ticket 29322在Django 2.1中解决的。