I'm seeing weird outputs while trying to order_by booleanfield in postgresql.
I have a boolean field with default=false and I'm using the order_by(-thebooleanfield) and something I see the True value first which is what I expected but something the False values come first.
Do I need to switch to different type? Or there is a correct way to order_by booleanfield in postgresql?
10x
Django is ordering by the value stored in the underlying database. I've never found any official explanation in the Django documentation, but there was a Django ticket a while back that explains it:
https://code.djangoproject.com/ticket/19726
Basically, the devs marked it as wontfix because implementing a consistent behaviour between database backends would make them more fragile.
The best way to ensure consistent behaviour is probably to sort the values client-side.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With