Tag Archives: :Related Field got invalid lookup: icontains

[Solved] Search with xadmin_ Related field got invalid lookup: icontains

Add these three fields to the class defined in the adminx.py file
list_display = ['code','email','send_type','send_time'] # the type of fields to display
search_fields = ['code','email','send_type'] # fields to search (all fields together) No fields with foreign keys here
list_filter = ['code','email','send_type','send_time'] # fields searched (single field search) and time

1.Problem description

When using xadmin to realize Django background function, use search_ Fields = [field name, field name], related field got invalid lookup: icons

2.Problem analysis

search_ Fields controls the name of the field that can be searched through the search box_ Fields = () or search_ Fields = [], xadmin uses fuzzy query

The search of related fields is invalid because search_ For example, if the field type is ForeignKey, an error will be reported

3.Solutions

Delete search_ Fields, for example, delete the field type ForeignKey