问题描述
我正在使用 Tortoise-ORM,我认为它基于 Django-ORM。
假设我的数据库如下所示:
class Recipe(Model):
description = fields.CharField(max_length=1024)
ingredients = fields.ManyToManyField(model_name="models.Ingredient",on_delete=fields.SET_NULL)
class Ingredient(Model):
name = fields.CharField(max_length=128)
是否可以使用单个内置的过滤器方法来查询名称为“番茄”和“洋葱”的所有食谱?
更新 #1
我尝试使用:Recipe.filter(Q(ingredients__name='tomato') & Q(ingredients__name='onion'))
select "recipe.id","recipe.description"
from "recipe"
left outer join "recipe_ingredient"
on "recipe.id" = "recipe_ingredient.recipe_id"
left outer join "ingredient"
on "recipe_ingredient.ingredient_id" = "ingredient.id"
where (
"ingredient.name" = 'tomato'
and "ingredient.name" = 'potato'
)
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)