Django: ordering numerical value with order_by

前端 未结 8 1930
陌清茗
陌清茗 2020-12-01 08:11

I\'m in a situation where I must output a quite large list of objects by a CharField used to store street addresses.

My problem is, that obviously the data is ordere

8条回答
  •  无人及你
    2020-12-01 08:29

    Great tip! It works for me! :) That's my code:

    revisioned_objects = revisioned_objects.extra(select={'casted_object_id': 'CAST(object_id AS INTEGER)'}).extra(order_by = ['casted_object_id'])
    

提交回复
热议问题