Change rack ordering in rack list and elevations list #2631

Closed
opened 2025-12-29 18:20:40 +01:00 by adam · 2 comments
Owner

Originally created by @subzer0iq on GitHub (May 23, 2019).

Environment

  • Python version: 3.6.7
  • NetBox version: 2.5.12

Proposed Functionality

Currently, Netbox displays racks sorted like this,
### NetBox interactive shell (test-office-1)
### Python 3.6.7 | Django 2.2.1 | NetBox 2.5.12
### lsmodels() will show available models. Use help(<model>) for more info.
>>> for i in Rack.objects.filter(site__name='DC2'):
... print(i)
...
R1/1/7 (R4/1/7)
R1/1/9 (R4/1/9)
R1/1/8A (R4/1/8A)

Racks-NetBox1

Any letter present in the end of the rack name, sends this rack in the bottom of list.
Alternative: use sorting by name:
### NetBox interactive shell (test-office-1)
### Python 3.6.7 | Django 2.2.1 | NetBox 2.5.12
### lsmodels() will show available models. Use help(<model>) for more info.
>>> for i in Rack.objects.filter(site__name='DC2').order_by('name'):
... print(i)
...
R1/1/7 (R4/1/7)
R1/1/8A (R4/1/8A)
R1/1/9 (R4/1/9)
>>>

Racks-NetBox2

Use Case

Ordiring by name is more human readable.

Database Changes

None

External Dependencies

None

Originally created by @subzer0iq on GitHub (May 23, 2019). <!-- NOTE: This form is only for proposing specific new features or enhancements. If you have a general idea or question, please post to our mailing list instead of opening an issue: https://groups.google.com/forum/#!forum/netbox-discuss NOTE: Due to an excessive backlog of feature requests, we are not currently accepting any proposals which significantly extend NetBox's feature scope. Please describe the environment in which you are running NetBox. Be sure that you are running an unmodified instance of the latest stable release before submitting a bug report. --> ### Environment * Python version: 3.6.7<!-- Example: 3.5.4 --> * NetBox version: 2.5.12<!-- Example: 2.3.6 --> <!-- Describe in detail the new functionality you are proposing. Include any specific changes to work flows, data models, or the user interface. --> ### Proposed Functionality Currently, Netbox displays racks sorted like this, `### NetBox interactive shell (test-office-1)` `### Python 3.6.7 | Django 2.2.1 | NetBox 2.5.12` `### lsmodels() will show available models. Use help(<model>) for more info.` `>>> for i in Rack.objects.filter(site__name='DC2'):` `... print(i)` `...` `R1/1/7 (R4/1/7)` `R1/1/9 (R4/1/9)` `R1/1/8A (R4/1/8A)` ![Racks-NetBox1](https://user-images.githubusercontent.com/30766229/58236501-b4bfd200-7d4b-11e9-8115-1670ac0e3812.png) Any letter present in the end of the rack name, sends this rack in the bottom of list. Alternative: use sorting by name: `### NetBox interactive shell (test-office-1)` `### Python 3.6.7 | Django 2.2.1 | NetBox 2.5.12` `### lsmodels() will show available models. Use help(<model>) for more info.` `>>> for i in Rack.objects.filter(site__name='DC2').order_by('name'):` `... print(i)` `...` `R1/1/7 (R4/1/7)` `R1/1/8A (R4/1/8A)` `R1/1/9 (R4/1/9)` `>>> ` ![Racks-NetBox2](https://user-images.githubusercontent.com/30766229/58236735-357ece00-7d4c-11e9-9389-2e0321bd97eb.png) <!-- Convey an example use case for your proposed feature. Write from the perspective of a NetBox user who would benefit from the proposed functionality and describe how. ---> ### Use Case Ordiring by name is more human readable. <!-- Note any changes to the database schema necessary to support the new feature. For example, does the proposal require adding a new model or field? (Not all new features require database changes.) ---> ### Database Changes None <!-- List any new dependencies on external libraries or services that this new feature would introduce. For example, does the proposal require the installation of a new Python package? (Not all new features introduce new dependencies.) --> ### External Dependencies None
adam closed this issue 2025-12-29 18:20:40 +01:00
Author
Owner

@jeremystretch commented on GitHub (May 27, 2019):

Racks and several other objects in NetBox employ NaturalOrderingManager to order names as a human would expect to see them. This presents, for example, Rack 11 from appearing in the list before Rack 2, which would happen if racks were ordered alphabetically by name as you suggest.

Unfortunately you've run into a corner case using dissimilar names, where the natural ordering logic doesn't work well. I'm open to suggestions for improvement to the logic with NaturalOrderingManager, however ordering by name only would break ordering for far more common uses cases, so I'm going to close this out.

@jeremystretch commented on GitHub (May 27, 2019): Racks and several other objects in NetBox employ [NaturalOrderingManager](https://github.com/digitalocean/netbox/blob/develop/netbox/utilities/managers.py#L8) to order names as a human would expect to see them. This presents, for example, Rack 11 from appearing in the list before Rack 2, which would happen if racks were ordered alphabetically by name as you suggest. Unfortunately you've run into a corner case using dissimilar names, where the natural ordering logic doesn't work well. I'm open to suggestions for improvement to the logic with NaturalOrderingManager, however ordering by `name` only would break ordering for far more common uses cases, so I'm going to close this out.
Author
Owner

@DanSheps commented on GitHub (May 28, 2019):

Just thinking out loud, but could we allow plugable order Managers per model maybe?

Default would be the regular NaturalOrderingManager and users could extend it as they see fit (or swapping it out for another default one).

@DanSheps commented on GitHub (May 28, 2019): Just thinking out loud, but could we allow plugable order Managers per model maybe? Default would be the regular NaturalOrderingManager and users could extend it as they see fit (or swapping it out for another default one).
Sign in to join this conversation.
1 Participants
Notifications
Due Date
No due date set.
Dependencies

No dependencies set.

Reference: starred/netbox#2631