相关疑难解决方法(0)

Django,从模型方法查询过滤

我有这些模型:

def Foo(Models.model):
    size = models.IntegerField()
    # other fields

    def is_active(self):
         if check_condition:
              return True
         else:
              return False

def Bar(Models.model):
     foo = models.ForeignKey("Foo")
     # other fields
Run Code Online (Sandbox Code Playgroud)

现在我想要查询具有活动Foo的条形码:

Bar.objects.filter(foo.is_active())
Run Code Online (Sandbox Code Playgroud)

我收到的错误如

SyntaxError at /
('non-keyword arg after keyword arg'
Run Code Online (Sandbox Code Playgroud)

我怎样才能做到这一点?

python django django-models django-orm django-queryset

63
推荐指数
4
解决办法
4万
查看次数