【问题标题】:Sorting numerically get order as 1,2,3 not 1, 10, 11, 12 in Django Python [duplicate]在 Django Python 中,数字排序为 1、2、3 而不是 1、10、11、12 [重复]
【发布时间】:2013-09-30 12:17:39
【问题描述】:

关于 mysql 的 this,我在我的 Django 代码中尝试了以下操作

myQuery.order_by('myColumn+0')


myQuery.order_by('myColumn'+0)

但没有一个对我有用

【问题讨论】:

标签: python django


【解决方案1】:

感谢 ppeterka 66 找到了解决方案

myQuery.filter().extra(
    select={'myinteger': 'CAST(mycharfield AS UNSIGNED)'}
).order_by('myinteger')

我用的是UNSIGNED而不是INTEGER,我猜我的mysql不支持它

【讨论】:

    猜你喜欢
    • 2010-12-22
    • 2018-07-23
    • 2019-06-05
    • 1970-01-01
    • 2017-02-25
    • 1970-01-01
    • 1970-01-01
    • 2023-01-16
    • 2018-06-04
    相关资源
    最近更新 更多