我正在读这个
我试图用like field
查询dtabase但是我收到错误
FieldError:不允许加入字段'car'。你是否 misspell'like'用于查找类型?
我的代码是
def formfield_for_manytomany(self, db_field, request, **kwargs):
if db_field.name == "cars":
kwargs["queryset"] = models.Cars.objects.filter(car_like="ford")
return super(MyAdmin, self).formfield_for_manytomany(db_field, request, **kwargs)
答案 0 :(得分:0)
发布的代码不会抛出此错误。如果您使用双下划线car__like
,它只会混淆连接。 You should check out the django query reference for exact details.
无论如何,perhaps you are looking for __icontains
生成一个LIKE语句?
Foo.objects.filter(some_field__icontains='ford')