Troubleshooting “Related Field has invalid lookup: icontains”

后端 未结 8 870
萌比男神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:11

    This may not answer the original question, but, every so often I run into a similar invalid lookup error because I accidentally used _set in a lookup, e.g. _set instead of just .

    Basically, I tend to confuse the related_query_name with the default_related_name , which does include _set (also see queries docs and related manager docs).

    From the lookups documentation:

    It works backwards, too. Whilst it can be customized, by default you refer to a “reverse” relationship in a lookup using the lowercase name of the model.

    (my emphasis)

    Confusing thing is that the default related_name (i.e. _set) is not the same as the default related_query_name (i.e. ), but if you set a custom related_name (or default_related_name, via model Meta options), that will also be used as the default related_query_name (as mentioned in the docs).

提交回复
热议问题