Django, query filtering from model method

前端 未结 5 529
醉酒成梦
醉酒成梦 2020-12-05 01:48

I have these models:

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

    def is_active(self):
         if check_condition:
               


        
5条回答
  •  自闭症患者
    2020-12-05 02:13

    You can't filter on methods, however if the is_active method on Foo checks an attribute on Foo, you can use the double-underscore syntax like Bar.objects.filter(foo__is_active_attribute=True)

提交回复
热议问题