How to add filter/search logic to django admin.TabularInline

2.8k Views Asked by At

I need to add ability to search or filter inline data (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)))

I tried to add list_search and list_filter to the definition, but it has no effect inside django admin.

Any suggestions?

1

There are 1 best solutions below

1
On

Here are the available options for admin.TabularInline : django doc

You probably want to use filter_horizontal and filter_vertical