How to order a Django QuerySet string property numerically?
I have a QuerySet, and I would like to order them numerically. The issue is the data is store开发者_如何转开发d as a String. I know how to do this in SQL or a list, but not a query set. Is this even possible?
You'll probably need to fallback to Django's extra function. Perhaps:
ordered = (qs.extra(select={"order_column": "CONVERT(column, INTEGER)"})
.order_by("order_column"))
(Assuming you're using MySQL)
精彩评论