You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Django admin配置list_filter报错people__type非有效字段问题问询

问题原因

  • list_filter 属性缩进错误,当前代码中它定义在 PeopleAdmin 类的外部,不属于Admin类的配置属性,Django无法识别这是你给People后台配置的筛选规则。
  • list_filter 的值配置错误,你当前是给People模型本身配置Admin后台,筛选自身字段直接写字段名即可,people__type 是关联模型跨表查询的写法,不适用于当前场景。

修正后的admin.py代码

from django.contrib import admin
from django.db import models
from .models import *
from tinymce.widgets import TinyMCE

# Register your models here.
class PeopleAdmin(admin.ModelAdmin):
    fieldsets = [
        ("Type", {"fields": ["type"]}),
        ("Information", {"fields": ["people_name",
                                    "people_surname",
                                    "people_phone_number",
                                    "people_email",
                                    "people_occupation",
                                    "people_revenue"]}),
        ("URL", {"fields": ["people_slug"]}),
    ]
    # 缩进移到类内部,直接使用字段名type
    list_filter = ('type',)

admin.site.register(People, PeopleAdmin)

内容的提问来源于stack exchange,提问作者bsaoptima

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.10.04 02:30:02