Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

views.AutocompleteJsonView fix for Django>=3.2 #79

Open
wants to merge 2 commits into
base: pre_release
Choose a base branch
from

Conversation

millioner
Copy link

Custom autocomplete view fails with Django>=3.2

This code

    def get_urls(self) -> List:
        from admin_auto_filters.views import AutocompleteJsonView
        custom_urls = [
            path(
                'autocomplete/',
                self.admin_site.admin_view(
                    AutocompleteJsonView.as_view(model_admin=self),
                ),
                name='autocomplete',
            ),
        ]
        return custom_urls + super().get_urls()

Gives this error:

TypeError: AutocompleteJsonView() received an invalid keyword 'model_admin'. as_view only accepts arguments that are already attributes of the class.

The reason: django.contrib.admin.views.AutocompleteJsonView class creates the model_admin property only during a requst processing.

Here is the commit in the Django repo - django/django@3071660

@bn-rv
Copy link

bn-rv commented May 13, 2022

self.term, self.model_admin, self.source_field, _ = self.process_request(request)
File "...django/contrib/admin/views/autocomplete.py", line 82, in process_request
model_admin = self.admin_site._registry[remote_model]
AttributeError: 'NoneType' object has no attribute '_registry'

@millioner
Copy link
Author

Yep, my bad. Docs are bit updated now.

@shaig-planetly
Copy link

@millioner I tested but this doesn't fix the issues for django>=3.2. Thanks for the PR btw!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants