wagtail-nest / wagtail-modeladmin

Add any model in your project to the Wagtail admin. Formerly wagtail.contrib.modeladmin.
Other
21 stars 8 forks source link

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

Open alexwayne opened 1 year ago

alexwayne commented 1 year ago

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.

Technical details

quique commented 6 months ago

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.