我可以将相关对象的{ errorCode: 400 //error goes here,
errorMessage: "my error mesage"}
更改为下拉菜单。问题是当我想过滤相关对象的相关对象时:
list_filter
当我想用class Match(Model):
team = models.ForeignKey('Team'...)
away_team = ... (doesn't matter)
class Team(Model):
country = models.ForeignKey('Country'...)
过滤Match
个对象时,我会这样做:
Team
对于list_filter = ['team__country']
这个过滤器,我使用https://github.com/mrts/django-admin-list-filter-dropdown:
dropdown
当我想通过 list_filter[('team',RelatedDropdownFilter)]
中的Match
来过滤Country
个对象时:
Team
但是当我想从此过滤器中创建下拉列表时,它不起作用:
list_filter = ['team__country']
它看起来与未指定list_filter = [('team__country',RelatedDropdownFilter)]
相同。
RelatedDropdownFilter
RelatedDropdownFilter
模板
class RelatedDropdownFilter(RelatedFieldListFilter):
template = 'django_admin_listfilter_dropdown/dropdown_filter.html'
你知道我该怎么办吗?
答案 0 :(得分:2)
您的模板正在检查是否有四个以上的选择:
{% if choices|slice:”4:” %}
我的猜测是,您正在查看的测试数据中的选择不超过四个。
只需删除该检查,并始终在该块中使用<select>
,或添加更多测试数据。这些选择是基于现有数据构建的,而不是简单地包括所有可能的值。