Django ORM 中 F 表达式的逻辑 OR

use*_*081 5 sqlite django postgresql orm

我有一个查询,例如

User.objects.annotate(
    x=Value(False, output_field=BooleanField()),
    y=Value(True, output_field=BooleanField())
).annotate(
    z=F('x').bitor(F('y'))  # HOW TO DO THIS?
).values('z')
Run Code Online (Sandbox Code Playgroud)

它适用于 SQLite,但不适用于 PostgreSQL。错误是

LINE 1: SELECT (false | true) AS "z" FROM "auth_user"  LIMIT 21
                      ^
HINT:  No operator matches the given name and argument types. You might need to add explicit type casts.
Run Code Online (Sandbox Code Playgroud)

我应该如何在带注释的字段上实现一致的逻辑或?

谢谢。

Nat*_*let 2

使用按位运算符时将其转换为整数类型

from django.db.models.functions import Cast

User.objects.annotate(
    x=Value(False, output_field=BooleanField()),
    y=Value(True, output_field=BooleanField())
).annotate(
    z=Cast(Cast(F('x'), IntergerField()).bitor(Cast(F('y'), IntergerField())), BooleanField())
).values('z')
Run Code Online (Sandbox Code Playgroud)