Django, query filtering from model method

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

    class Page(models.Model):
        category = models.ForeignKey(Category)
        title = models.CharField(max_length=128)
        url = models.URLField()
    ...
    
    class Category(models.Model):
        ...
        open = models.BooleanField(default=True)
    

    May be you can use simple filter, for this type of conditions.

    Page.objects.filter(category__open=True)
    

提交回复
热议问题