How to filter choices in Django2’s autocomplete_fields?
If you are using autocomplete_fields for a ManyToManyField on ‘self’, this example will exclude the current object. Get the current object’s id by overriding get_form: field_for_autocomplete = None def get_form(self, request, obj=None, **kwargs): if obj: self.field_for_autocomplete = obj.pk return super(MyAdmin, self).get_form(request, obj, **kwargs) Next, override get_search_results. Modify the queryset only for your model’s autocomplete URI: … Read more