[Answered ]-Django filter dynamic field name based on queryset

1👍

You use an .alias(…) [Django-doc] for the expression, and then .filter(…) [Django-doc] on that alias:

queryset.alias(
    my_price=Case(
        When(price_after_static_discount=0, then=F('price')),
        default=F('price_after_discount'),
    )
).filter(my_price__lt=value)

Leave a comment