Skip to content

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

@alexwayne

Description

@alexwayne

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    status:UnconfirmedIssue, usually a bug, that has not yet been validated as a confirmed problem.type:BugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions