Wednesday, August 29, 2018

Re: How to filter choices in Django2's autocomplete_fields?

You need to override  ModelAdmin.get_search_results()  as per

My problem is I override ForeignKeyField in AdminForm, where I can filter based on self.instance, this is not possible in current implementation AFAICS? The instance ID would have to be passed to the autocomplete_view

On Monday, 8 January 2018 16:49:56 UTC, Oren wrote:

In Django 2.0, autocomplete_fields was added, which is great.

Without autocomplete_fields, I can change the queryset of a ForeignKeyField using formfield_for_foreignkey.

But combining the two together doesn't work - it looks like the list of options for autocomplete is dynamic and coming from a different url, instead of from the current form.

So the question is -

How can I change the queryset in the autocomplete widget?


You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to
To post to this group, send email to
Visit this group at
To view this discussion on the web visit
For more options, visit

No comments:

Post a Comment