Explorar o código

Tweak queryset for Service views to prefetch related IPs with unrestricted()

Jeremy Stretch %!s(int64=5) %!d(string=hai) anos
pai
achega
9f025747a7
Modificáronse 1 ficheiros con 6 adicións e 2 borrados
  1. 6 2
      netbox/ipam/views.py

+ 6 - 2
netbox/ipam/views.py

@@ -809,7 +809,9 @@ class ServiceListView(ObjectListView):
 
 
 class ServiceView(ObjectView):
-    queryset = Service.objects.all()
+    queryset = Service.objects.prefetch_related(
+        Prefetch('ipaddresses', IPAddress.objects.unrestricted())
+    )
 
     def get(self, request, pk):
 
@@ -821,7 +823,9 @@ class ServiceView(ObjectView):
 
 
 class ServiceEditView(ObjectEditView):
-    queryset = Service.objects.all()
+    queryset = Service.objects.prefetch_related(
+        Prefetch('ipaddresses', IPAddress.objects.unrestricted())
+    )
     model_form = forms.ServiceForm
     template_name = 'ipam/service_edit.html'