Skip to content

Commit 00d72f1

Browse files
committed
Annotate need for natural ordering
1 parent b36afdc commit 00d72f1

File tree

1 file changed

+5
-6
lines changed

1 file changed

+5
-6
lines changed

netbox/dcim/views.py

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -589,19 +589,18 @@ def get(self, request):
589589
racks = filtersets.RackFilterSet(request.GET, self.queryset).qs
590590
total_count = racks.count()
591591

592+
# Ordering
592593
ORDERING_CHOICES = {
593594
'name': 'Name (A-Z)',
594595
'-name': 'Name (Z-A)',
595596
'facility_id': 'Facility ID (A-Z)',
596597
'-facility_id': 'Facility ID (Z-A)',
597598
}
598-
sort = request.GET.get('sort', "name")
599+
sort = request.GET.get('sort', 'name')
599600
if sort not in ORDERING_CHOICES:
600601
sort = 'name'
601-
sort_choice = sort
602-
sort = sort.replace("name", "_name")
603-
604-
racks = racks.order_by(sort)
602+
sort_field = sort.replace("name", "_name") # Use natural ordering
603+
racks = racks.order_by(sort_field)
605604

606605
# Pagination
607606
per_page = get_paginate_count(request)
@@ -624,7 +623,7 @@ def get(self, request):
624623
'page': page,
625624
'total_count': total_count,
626625
'sort': sort,
627-
'sort_display_name': ORDERING_CHOICES[sort_choice],
626+
'sort_display_name': ORDERING_CHOICES[sort],
628627
'sort_choices': ORDERING_CHOICES,
629628
'rack_face': rack_face,
630629
'filter_form': forms.RackElevationFilterForm(request.GET),

0 commit comments

Comments
 (0)