django-admin-autocomplete-filter
django-admin-autocomplete-filter copied to clipboard
Problem with nplus one package
Thank you for this awesome package. Really helped a lot.
But then I enable nplusone middleware and try to load admin page with autocomplete filter - server returned 500 error
site-packages/nplusone/ext/django/patch.py", line 137, in parse_forward_many_to_one_queryset
instance = context['kwargs']['instance']
KeyError: 'instance'
The default django-admin ModelAdmin.autocomplete_fields
are working without any problems with this middleware, so maybe something from AutocompleteFilter is missing?
If you can have a look at this it would be great.
Does anybody resolve the problem? Or everyone is turned off nplusone
and only turn it on when you need it?
It is curious to have this error from nplusone reported to the django-admin-autocomplete-filter. The traceback does not show d-a-a-f. No inspection of the error (using pdb for example) is done. It would be useful if one of the people who see the problem could look deeper.
It work.
from admin_auto_filters.filters import AutocompleteFilter as BaseAutocompleteFilter
from django.conf import settings
class AutocompleteFilter(BaseAutocompleteFilter):
def __init__(self, request, params, model, model_admin):
if 'nplusone.ext.django' in settings.INSTALLED_APPS:
from nplusone.core import signals
with signals.ignore(signals.lazy_load):
super().__init__(request, params, model, model_admin)
else:
super().__init__(request, params, model, model_admin)