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

Bug in 'render' function of 'ForeignKeySearchInput' class in 'admin/widgets.py' file #968

Closed
StasD opened this issue Sep 29, 2016 · 2 comments

Comments

@StasD
Copy link

StasD commented Sep 29, 2016

Hello,

I believe there is a bug in 'render' function of 'ForeignKeySearchInput' class in admin/widgets.py file. When it creates the url for 'search_path', it should look at the other side of the relationship, because of the way new 'foreignkey_autocomplete' url resolver is added to the admin site in 'get_urls' function of 'ForeignKeyAutocompleteAdmin' class in admin/__init__.py file.

So, in 'render' function of 'ForeignKeySearchInput' class, the code should look something like this:

        opts = self.rel.to._meta
        app_label = opts.app_label
        model_name = opts.object_name.lower()
        related_url = reverse('admin:%s_%s_changelist' % (app_label, model_name))

        if not self.search_path:
            opts_1 = self.rel.related_model._meta
            app_label_1 = opts_1.app_label
            model_name_1 = opts_1.object_name.lower()
            related_url_1 = reverse('admin:%s_%s_changelist' % (app_label_1, model_name_1))
            self.search_path = urllib.parse.urljoin(related_url_1, 'foreignkey_autocomplete/')

The way it is now, the inline lookup will not work in general case. It will only work if the model corresponding to the 'to' side of relationship is independently registered on admin site by using ForeignKeyAutocompleteAdmin, too. The bug probably dates back to version 1.6.0.

P.S.: While writing this post, I realized that the workaround would probably be to just derive all the required models on the admin site using 'ForeignKeyAutocompleteAdmin' rather than 'ModelAdmin'. :)

@trbs
Copy link
Member

trbs commented Oct 9, 2016

Any chance of writing some unittests and maybe a PR for this ?

@trbs
Copy link
Member

trbs commented Aug 27, 2018

closing due to inactivity

@trbs trbs closed this as completed Aug 27, 2018
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

No branches or pull requests

2 participants