mirror of
https://github.com/netbox-community/netbox.git
synced 2024-05-10 07:54:54 +00:00
Annotate need for natural ordering
This commit is contained in:
committed by
Jeremy Stretch
parent
b36afdc924
commit
00d72f18cf
@ -589,19 +589,18 @@ class RackElevationListView(generic.ObjectListView):
|
|||||||
racks = filtersets.RackFilterSet(request.GET, self.queryset).qs
|
racks = filtersets.RackFilterSet(request.GET, self.queryset).qs
|
||||||
total_count = racks.count()
|
total_count = racks.count()
|
||||||
|
|
||||||
|
# Ordering
|
||||||
ORDERING_CHOICES = {
|
ORDERING_CHOICES = {
|
||||||
'name': 'Name (A-Z)',
|
'name': 'Name (A-Z)',
|
||||||
'-name': 'Name (Z-A)',
|
'-name': 'Name (Z-A)',
|
||||||
'facility_id': 'Facility ID (A-Z)',
|
'facility_id': 'Facility ID (A-Z)',
|
||||||
'-facility_id': 'Facility ID (Z-A)',
|
'-facility_id': 'Facility ID (Z-A)',
|
||||||
}
|
}
|
||||||
sort = request.GET.get('sort', "name")
|
sort = request.GET.get('sort', 'name')
|
||||||
if sort not in ORDERING_CHOICES:
|
if sort not in ORDERING_CHOICES:
|
||||||
sort = 'name'
|
sort = 'name'
|
||||||
sort_choice = sort
|
sort_field = sort.replace("name", "_name") # Use natural ordering
|
||||||
sort = sort.replace("name", "_name")
|
racks = racks.order_by(sort_field)
|
||||||
|
|
||||||
racks = racks.order_by(sort)
|
|
||||||
|
|
||||||
# Pagination
|
# Pagination
|
||||||
per_page = get_paginate_count(request)
|
per_page = get_paginate_count(request)
|
||||||
@ -624,7 +623,7 @@ class RackElevationListView(generic.ObjectListView):
|
|||||||
'page': page,
|
'page': page,
|
||||||
'total_count': total_count,
|
'total_count': total_count,
|
||||||
'sort': sort,
|
'sort': sort,
|
||||||
'sort_display_name': ORDERING_CHOICES[sort_choice],
|
'sort_display_name': ORDERING_CHOICES[sort],
|
||||||
'sort_choices': ORDERING_CHOICES,
|
'sort_choices': ORDERING_CHOICES,
|
||||||
'rack_face': rack_face,
|
'rack_face': rack_face,
|
||||||
'filter_form': forms.RackElevationFilterForm(request.GET),
|
'filter_form': forms.RackElevationFilterForm(request.GET),
|
||||||
|
Reference in New Issue
Block a user