Add a custom expression. Below uses CASE
statement, but you could use IF
as well if you db supports it:
@is_ok.expression
def is_ok(cls):
return case([(cls.status > 0, True)], else_=False).label("is_ok")
See Defining Expression Behavior Distinct from Attribute Behavior
documentation for more info.