Skip to content

Commit

Permalink
Fixes #747: Fixes natural_order_by integer cast error on large numbers
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremystretch committed Dec 19, 2016
1 parent fc147fe commit e5e32d8
Showing 1 changed file with 2 additions and 2 deletions.
4 changes: 2 additions & 2 deletions netbox/utilities/managers.py
Expand Up @@ -21,9 +21,9 @@ def natural_order_by(self, *fields):
id3 = '_{}_{}3'.format(db_table, primary_field)

queryset = super(NaturalOrderByManager, self).get_queryset().extra(select={
id1: "CAST(SUBSTRING({}.{} FROM '^(\d+)') AS integer)".format(db_table, primary_field),
id1: "CAST(SUBSTRING({}.{} FROM '^(\d{{1,9}})') AS integer)".format(db_table, primary_field),
id2: "SUBSTRING({}.{} FROM '^\d*(.*?)\d*$')".format(db_table, primary_field),
id3: "CAST(SUBSTRING({}.{} FROM '(\d+)$') AS integer)".format(db_table, primary_field),
id3: "CAST(SUBSTRING({}.{} FROM '(\d{{1,9}})$') AS integer)".format(db_table, primary_field),
})
ordering = fields[0:-1] + (id1, id2, id3)

Expand Down

0 comments on commit e5e32d8

Please sign in to comment.