#32659: Autocomplete field: The results could not be loaded.
-------------------------------+--------------------------------------
     Reporter:  honyczek       |                    Owner:  nobody
         Type:  Bug            |                   Status:  closed
    Component:  contrib.admin  |                  Version:  3.2
     Severity:  Normal         |               Resolution:  needsinfo
     Keywords:                 |             Triage Stage:  Unreviewed
    Has patch:  0              |      Needs documentation:  0
  Needs tests:  0              |  Patch needs improvement:  0
Easy pickings:  0              |                    UI/UX:  0
-------------------------------+--------------------------------------

Comment (by selected-pixel-jameson):

 I've run into this exact issue on my project. I'm assuming there is a
 conflict between the Django Autocomplete Light dependency and Django 3.2
 autocomplete_fields.

 I'm looking at your example fix below, but I'm not sure where you are
 implementing this in your Django Project?

 Replying to [comment:9 Erik van Widenfelt]:
 > This had nothing to do with caching or `collectstatic` for me. I traced
 it to the `admin_site` attribute of `AutocompleteJsonView`.The view tries
 to get the `model_admin` class for the `remote model` from Django's
 default admin site. If you registered your remote model in a custom admin
 site a `KeyError` is raised (line 84). This behavior has changed from
 3.1.12 to 3.2.0. See changes in commit
 3071660acfbdf4b5c59457c8e9dc345d5e8894c5.
 >
 > A quick/dirty fix is to scan through the registered `AdminSites` in
 `all_sites` for the `admin_site ` that has registered the `remote_model`:
 >
 > {{{
 >
 > # django/contrib/admin/views/autocomplete.py
 >
 > from django.contrib.admin.sites import all_sites
 >
 > class AutocompleteJsonView(BaseListView):
 >     ....
 >
 >     def process_request(self, request):
 >
 >         ....
 >
 >        # find the correct admin site for this remote model
 >         try:
 >             admin_site = [s for s in all_sites if
 s.is_registered(remote_model)][0]
 >         except IndexError as e:
 >             raise PermissionDenied from e
 >
 >         # continue as before and get the model admin class from the
 admin site
 >         try:
 >             model_admin = admin_site._registry[remote_model]
 >         except KeyError as e:
 >             raise PermissionDenied from e
 >
 >         # Validate suitability of objects.
 >         ....
 > }}}
 >
 > Note that you cannot just register the `remote_model` with the default
 admin site. The `remote_model` needs to be registered to the same admin
 class as the `source_model`.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/32659#comment:14>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/066.873f427879d5f4be852713fdf9039c0d%40djangoproject.com.

Reply via email to