Find centralized, trusted content and collaborate around the technologies you use most.
Teams
Q&A for work
Connect and share knowledge within a single location that is structured and easy to search.
我有一个 Django 查询集,我必须在其中使用该.extra(select=)方法,因为我正在计算一个需要WHERE语句子过滤器的字段。
.extra(select=)
WHERE
我在很多地方都使用了这个WHERE子句,并且我希望遵守 DRY(这在编写原始 SQL 时通常有些困难)。我使用 Django 的Q()对象编写了一个语句,我可以重用并添加到原始 SQL 中。
Q()
我知道你可以做得到Queryset.query.__str__()等效的 SQL 输出——有没有办法用Q对象做到这一点?
Queryset.query.__str__()
Q