模型,执行OR和ORDER by

2024-09-30 18:19:11 发布

您现在位置:Python中文网/ 问答频道 /正文

我有以下型号:

Class Category(models.Model):
    ....

Class CategoryProduct(models.Model):
    ....
    position  = models.IntegerField(max_length=3)


class Product(models.Model):
    .....

我正在执行以下查询:

return Product.objects.filter(categoryproduct__category=self, active=True) | \
           Product.objects.filter(categoryproduct__category__category=self, active=True)

如何获得按categoryproduct\uuuu位置排序的位置


Tags: selftruemodelobjectsmodelspositionproductfilter