我有以下代码:
class StartNumeric(Func):
function = 'REGEXP_MATCHES'
template = "(%(function)s(%(expressions)s, '^(\d+)|(\d+$)'))[1]::int"
class EndNumeric(Func):
function = 'REGEXP_MATCHES'
template = (
"%(function)s(%(expressions)s, '^(\w+)([0-9]+)|([0-9]+)|([a-z]+)$')")
class MyHistoryTable(tables.Table):
...some fields...
def order(self, queryset, is_descending):
queryset = queryset.annotate(
short_label_numeric=StartNumeric('field__short_label'),
short_label_char=EndNumeric('field__short_label')
).order_by(('-' if is_descending else '') + 'field_label_numeric', 'field_label_char', 'field__short_label')
return (queryset, True)
当我按ASC排序时:可以,结果是
2c 3c 5 7 9 10 11 12 13 14 15 16 17 19 20 21 22 23 24 25 26 27 28 29 30 32c 33c 35c 106 107 147 200c 260261261263263264 265fs 266fs 267c 268c 269c 273c 274c 275c 275c 276c 276c 501 502 503 504 506 507 511 512 520 521 603 604 610 611 611 623…S1 S2 S3 S4 S5 S6 S7 S9 S10 S11 S14 S19
但是当我按DESC排序时:结果的最后一部分是
... S1 S2 S3 S4 S5 S6 S7 S9 S10 S11 S14 S19
我如何更改EndNumeric正则表达式以获得
之类的结果S19 S14 S11 S10 S9 S7 S6 S5 S4 S3 S2 S1 ... 623611 ... 276c 275c 274c ... 147107106 ... 12 11 9 7 5 3c 2c
有人有什么假设吗?