| 1 | | 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 |
| | 1 | 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. |
| | 2 | |
| | 3 | A quick/dirty fix is to scan through the registered `AdminSites` in `all_sites` for the `admin_site ` that has registered the `remote_model`: |
| | 4 | |
| | 5 | {{{ |
| | 6 | |
| | 7 | # django/contrib/admin/views/autocomplete.py |
| | 8 | |
| | 9 | from django.contrib.admin.sites import all_sites |
| | 10 | |
| | 11 | .... |
| | 12 | |
| | 13 | # find the correct admin site for this remote model |
| | 14 | try: |
| | 15 | admin_site = [s for s in all_sites if s.is_registered(remote_model)][0] |
| | 16 | except IndexError as e: |
| | 17 | raise PermissionDenied from e |
| | 18 | |
| | 19 | # continue as before and get the model admin class from the admin site |
| | 20 | try: |
| | 21 | model_admin = admin_site._registry[remote_model] |
| | 22 | except KeyError as e: |
| | 23 | raise PermissionDenied from e |
| | 24 | |
| | 25 | # Validate suitability of objects. |
| | 26 | .... |
| | 27 | }}} |
| | 28 | |
| | 29 | 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`. |