具有LIMIT的Django Queryset,取决于Queryset条件/过滤器

时间:2018-07-26 09:16:26

标签: django django-queryset

我有一个模型Item和一个常量MAX_NR。

class Item(models.Model):

    is_featured = models.BooleanField()
    is_active = models.BooleanField()

使用查询集我想要得到:

  1. 所有具有is_active=Trueis_featured=True的项目,如果它们的数量大于MAX_NR

  2. 在记录is_active=True, is_featured=True之前具有is_active=True的项目以及具有MAX_NR的其他其他项目,如果is_featured=True的数目小于MAX_NR,由is_featured=True

  3. 排序

可以在一个查询集中完成吗?

0 个答案:

没有答案
相关问题