Skip to content

Commit

Permalink
Fixes #844: Apply order_naturally() to API interfaces list
Browse files Browse the repository at this point in the history
  • Loading branch information
jeremystretch committed Jan 25, 2017
1 parent fbfa3cf commit f3db914
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 5 deletions.
8 changes: 4 additions & 4 deletions netbox/dcim/api/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@

from django.conf import settings
from django.contrib.contenttypes.models import ContentType
from django.db.models import Count
from django.http import Http404
from django.shortcuts import get_object_or_404

Expand Down Expand Up @@ -332,7 +331,8 @@ class InterfaceListView(generics.ListAPIView):
def get_queryset(self):

device = get_object_or_404(Device, pk=self.kwargs['pk'])
queryset = Interface.objects.filter(device=device).select_related('connected_as_a', 'connected_as_b')
queryset = Interface.objects.order_naturally(device.device_type.interface_ordering).filter(device=device)\
.select_related('connected_as_a', 'connected_as_b', 'circuit_termination')

# Filter by type (physical or virtual)
iface_type = self.request.query_params.get('type')
Expand Down Expand Up @@ -490,8 +490,8 @@ def get(self, request):
response['power-ports'].append(data)

# Interface connections
interfaces = Interface.objects.filter(device=device).select_related('connected_as_a', 'connected_as_b',
'circuit_termination')
interfaces = Interface.objects.order_naturally(device.device_type.interface_ordering).filter(device=device)\
.select_related('connected_as_a', 'connected_as_b', 'circuit_termination')
for iface in interfaces:
data = serializers.InterfaceDetailSerializer(instance=iface).data
del(data['device'])
Expand Down
3 changes: 2 additions & 1 deletion netbox/dcim/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -749,7 +749,8 @@ def device_inventory(request, pk):
def device_lldp_neighbors(request, pk):

device = get_object_or_404(Device, pk=pk)
interfaces = Interface.objects.filter(device=device).select_related('connected_as_a', 'connected_as_b')
interfaces = Interface.objects.order_naturally(device.device_type.interface_ordering).filter(device=device)\
.select_related('connected_as_a', 'connected_as_b')

return render(request, 'dcim/device_lldp_neighbors.html', {
'device': device,
Expand Down

0 comments on commit f3db914

Please sign in to comment.