如何将过滤器/搜索逻辑添加到django admin.TabularInline

时间:2015-06-08 18:44:05

标签: django django-models django-admin

我需要添加搜索或过滤内联数据的功能(admin.TabularInline)

class CommandsInline(admin.TabularInline):
    model = Command
    readonly_fields = ('id', 'owner_phone_version', 'operation', 'command', 'options', 'created')
    exclude = ('owner', 'token', 'owner_phone', 'parameter', 'value')
    extra = 0
    max_num = 0
    ordering = ('-created',)


    def command(self, instance):
        return format_html(mark_safe("<b>%s</b>=%s" % (instance.parameter, instance.value)))
    def owner_phone_version(self, instance):
        return format_html(mark_safe("<b>%s</b>. <em>%s</em>" % (instance.owner_phone.id, instance.owner_phone.version)))

我尝试将list_search和list_filter添加到定义中,但它在django admin中没有任何效果。

有什么建议吗?

1 个答案:

答案 0 :(得分:0)

以下是admin.TabularInline的可用选项:django doc

您可能想要使用filter_horizontalfilter_vertical