Can't customize the choice of autocomplete_field with TabularInline Django

Viewed 34

I'm trying to limit the choice in autocomplete_field within TabularInline Django but I can't. I can do this within a ModelAdmin via get_search_results. But within TabularInline, it seems that the funtion get_search_results isn't called. Someone has any idea to do this with TabularInline?

class BarInline(admin.TabularInline):
    model = models.Bar
    extra = 0
    search_files = ('bar',)
    autocomplete_fields = ('bar',)

    def get_search_results(self, request, queryset, search_term):
        # I want to do something here to limit the choice of autocomplete_fields 'bar'.
        # But this function is never called within TabularInline
        # For exemple, I want to
        ...
        queryset = models.Bar.objects.filter(bar__name__contains="Only")
        ...


@admin.register(models.Foo)
class FooAdmin(ModelAdmin):
    inlines = (BarInline,)
0 Answers
Related