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

ModelAdmin: Unsupported lookup 'icontains' for ForeignKey or join on the field not permitted. #28

Open
alexwayne opened this issue May 24, 2023 · 1 comment
Labels
status:Unconfirmed Issue, usually a bug, that has not yet been validated as a confirmed problem. type:Bug Something isn't working

Comments

@alexwayne
Copy link

Issue Summary

When using model admin, if you have search_fields, and one of the fields is a foreign key, it raises the subject error:

Unsupported lookup 'icontains' for ForeignKey or join on the field not permitted.

Steps to Reproduce

  1. Add FieldPanels to a Django model that has at least one foreignkey:
  2. Add wagtail_hooks.py or edit it. Add search_fields and include the foreign key.
  3. Make sure the wagtail_hooks are referenced as ModelAdmin or ModelAdminGroup.
  4. Go to your website to the admin section for that model
  5. Add 'something' to the "search" box and click the search button.
  6. Witness the error

Any other relevant information. For example, why do you consider this a bug and what did you expect to happen instead?
Because it should be warned or considered in Wagtail, or consider in documentation how to refer to the foreign key str representation or an attribute of the foreign key.

  • I have confirmed that this issue can be reproduced as described on a fresh Wagtail project: (yes / no) No.

Technical details

  • Python version: Run python --version. 3.11.3
  • Django version: Look in your requirements.txt, or run pip show django | grep Version. 4.2.1
  • Wagtail version: Look at the bottom of the Settings menu in the Wagtail admin, or run pip show wagtail | grep Version:. 5.0
  • Browser version: You can use https://www.whatsmybrowser.org/ to find this out. Edge 113 https://www.whatsmybrowser.org/b/DP3T5
@alexwayne alexwayne added status:Unconfirmed Issue, usually a bug, that has not yet been validated as a confirmed problem. type:Bug Something isn't working labels May 24, 2023
@laymonage laymonage transferred this issue from wagtail/wagtail Jul 26, 2023
@quique
Copy link

quique commented Mar 1, 2024

Add search_fields and include the foreign key

Beware that you should use the double underscore notation to search a field on a related object.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status:Unconfirmed Issue, usually a bug, that has not yet been validated as a confirmed problem. type:Bug Something isn't working
Projects
None yet
Development

No branches or pull requests

2 participants