Django, query filtering from model method

前端 未结 5 536
醉酒成梦
醉酒成梦 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:00

    You could also use a custom manager. Then you could run something like this:

    Bar.objects.foo_active()
    

    And all you have to do is:

    class BarManager(models.Manager):
        def foo_active(self):
           # use your method to filter results
           return you_custom_queryset
    

    Check out the docs.

提交回复
热议问题