Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/django/23.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Django管理列表\过滤器自定义字段错误_Django - Fatal编程技术网

Django管理列表\过滤器自定义字段错误

Django管理列表\过滤器自定义字段错误,django,Django,我用额外的选项扩展了用户,比如department。但是当我尝试在管理面板上为DePartment添加过滤器时。它抛出以下错误: 错误: :(admin.E116)“列表过滤器[0]”的值指的是“部门”,而不是指字段 参考其外观: 除此之外: class UserAdmin(BaseUserAdmin): inlines = (EmployeeInline, ) list_display = ('username', 'email', 'first_name', 'last_name', 'ge

我用额外的选项扩展了用户,比如department。但是当我尝试在管理面板上为DePartment添加过滤器时。它抛出以下错误:

错误: :(admin.E116)“列表过滤器[0]”的值指的是“部门”,而不是指字段

参考其外观:

除此之外:

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

列表显示似乎工作正常。

您必须指定哪个型号的
部门

list_filter = ('employee__department',)

用户模型和员工模型有关系,所以您可以从带有员工字段的用户表中访问它。employee现在是用户的字段

list_filter = ('employee__department',)
员工是榜样。 而部门是员工的领域。 希望它应该为你工作我的一个正在工作下面是屏幕截图


我添加的图像只是为了说明目的,只是为了简单明了。