首页 > 解决方案 > Ormar 使用 LIKE 语句选择

问题描述

我在 Ormar 的文档中找不到使用LIKE. 有使用的示例select_relate,但我不需要链接表。

文档中有一个例子:

books = (
    await Book.objects.select_related("author")
        .filter(ormar.or_(
        ormar.and_(author__name__icontains="tolkien"), # one argument == just wrapped in ()
        ormar.and_(author__name__icontains="sapkowski")
    ))
        .all()

或者

books = (
    await Book.objects.select_related("author")
        .filter(
        (Book.author.name.icontains("tolkien")) |
        (Book.author.name.icontains("sapkowski"))
    ))                                      
        .all()
)

这个例子使用了author相关的表Books,但是应该怎么做才能按字段过滤Book呢?

标签: pythonormar

解决方案


推荐阅读