1👍
✅
let’s Imagine your model is called Order
, then your queryset will look like this.
preference = Case(
When(status="DELIVERED", then=Value(0)),
When(status="ON_ITS_WAY", then=Value(1)),
When(status="PACKAGING", then=Value(2))
)
query_set = Order.objects.alias(preference=preference).order_by('preference')
Check these methods from Official Django Docs:
Source:stackexchange.com