gpt4 book ai didi

Django admin list_filter 自定义字段错误

转载 作者:行者123 更新时间:2023-12-03 23:54:36 24 4
gpt4 key购买 nike

我用额外的选项扩展了用户,比如部门。但是当我尝试在管理面板为 derpartment 添加过滤器时。它抛出这个错误:

ERRORS: : (admin.E116) The value of 'list_filter[0]' refers to 'department', which does not refer to a Field.



引用它的外观: https://docs.djangoproject.com/en/1.11/topics/auth/customizing/#extending-user

有了这个补充:
class UserAdmin(BaseUserAdmin):
inlines = (EmployeeInline, )
list_display = ('username', 'email', 'first_name', 'last_name', 'get_department')
list_filter = ('department',)

def get_department(self, instance):
return instance.employee.department

列表显示似乎工作正常。

最佳答案

您必须指定哪个型号 department在。

list_filter = ('employee__department',)

关于Django admin list_filter 自定义字段错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50953753/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com