Troubleshooting “Related Field has invalid lookup: icontains”

后端 未结 8 865
萌比男神i
萌比男神i 2021-01-31 06:33

I have the following models in models.py:

class ListinoTraduttore(models.Model):
        traduttore = models.ForeignKey(\'Traduttore\', related_name=         


        
8条回答
  •  生来不讨喜
    2021-01-31 07:22

    This is to (hopefully) simplify the answer.

    Don't filter on a ForeignKey field itself!


    Change this

    search_fields = ['foreinkeyfield']
    

    to (notice TWO underscores)

    search_fields = ['foreinkeyfield__name']
    

    name represents the field-name from the table that we have a ForeinKey relationship with.

    Hope this helps

提交回复
热议问题