My Table
Id Data
-----------------
1 Yellow
2 Green
3 Red
4 Yellow
Using django query set (django 1.3.3, python 2.7, db Postgre), I want to order table by Data column as defined ordered [Yellow, Red, Green],
or order by first letter of Data column (which also give the same result)
Result
Id Data
-----------------
1 Yellow
4 Yellow
3 Red
2 Green
Please help how can I make this work
Update: How about order as [Green, Yellow, Red]
You can do:
YourModel.objects.order_by('-Data')
Note '-Data'
to order it in reverse order.
Reference: order_by
My Table
Id Data
-----------------
1 Yellow
2 Green
3 Red
4 Yellow
Using django query set (django 1.3.3, python 2.7, db Postgre), I want to order table by Data column as defined ordered [Yellow, Red, Green],
or order by first letter of Data column (which also give the same result)
Result
Id Data
-----------------
1 Yellow
4 Yellow
3 Red
2 Green
Please help how can I make this work
Update: How about order as [Green, Yellow, Red]
You can do:
YourModel.objects.order_by('-Data')
Note '-Data'
to order it in reverse order.
Reference: order_by
0 commentaires:
Enregistrer un commentaire