Django Фильтр дублирующихся объектов в квантовом наборе
У меня есть модель Product и ProductPrices.
class ProductPrice(BaseModel):
product = models.ForeignKey(
to="Product", related_name="prices", on_delete=models.CASCADE, verbose_name=_("prices"), null=True, blank=True
)
При попытке заказа по полю модели цены некоторые объекты дублируются. Что делать?
if order_by in [order_choices[HIGH_TO_LOW_PRICE], order_choices[LOW_TO_HIGH_PRICE]]:
outer_price = ProductPrice.objects.filter(end_user__isnull=False, product_id=OuterRef("pk"))
qs = qs.annotate(has_price=Exists(outer_price)).order_by("-has_price", order_by).distinct()
return qs