I've a simple query like this (I want 1 BHK to come first, then 2BHK, then anything else)
select *
from service_options
order by case space when '1BHK' then 0 when '2BHK' then 1 else 2 end,
space
In Django, how to do it? I've a model named ServiceOption
I tried this but no luck.
ServiceOption.objects.order_by(RawSQL("case space when '1BHK' then 0 when '2BHK' then 1 else 2 end,space"), ()).all()
I don't want to execute raw query with something like
ServiceOption.objects.raw("raw query here")
In Laravel, something like this could easily be pulled off like this
Model::query()->orderByRaw('raw order by query here')->get();
Any input will be appreciated. Thank you in advance.