2
You could change status to an IntegerField
, and define constants for the three states. Then sorting by ‘status’ should do what you want.
PENDING = 1
APPROVED = 2
CANCELED = 3
STATUS_CHOICES = (APPROVED,'Approved'),(PENDING, 'Pending'), (CANCELED, 'Canceled))
Or you could create a StatusChoice
model, with a field sort_order
. Make Reservation.status
a foreign key to the new model, and sort by status__sort_order
.
Another option would be to sort in SQL by using the order_by
parameter in extra()
.
Source:stackexchange.com