[Answered ]-Django Admin formfield_for_foreignkey for manytomany

1👍

Finally found the answer here: https://forum.djangoproject.com/t/django-admin-autocomplete-field-search-customization/7455/5

Which results in the following code:

@admin.register(Strecke)
class StreckeAdmin(admin.ModelAdmin):
    search_fields = ["name"]

    def get_search_results(self, request, queryset, search_term):
        print("get serach results")
        queryset = queryset.filter(auftrag_id__exact=8)
        qs = super().get_search_results(request, queryset, search_term)
        print(qs)
        return qs
👤rapsli

Leave a comment