8
0
Fork 0
mirror of https://gitlab2.federez.net/re2o/re2o synced 2024-12-25 08:23:46 +00:00

Fix et optimisation select_related

This commit is contained in:
Gabriel Detraz 2017-10-18 04:11:27 +02:00
parent ff22704262
commit 76e2226801
3 changed files with 7 additions and 2 deletions

View file

@ -533,7 +533,8 @@ def control(request):
facture_list = paginator.page(1)
except EmptyPage:
facture_list = paginator.page(paginator.num.pages)
page_query = Facture.objects.order_by('date').reverse().filter(
page_query = Facture.objects.order_by('date').select_related('user')\
.select_related('paiement').reverse().filter(
id__in=[facture.id for facture in facture_list]
)
controlform = controlform_set(request.POST or None, queryset=page_query)

View file

@ -380,6 +380,8 @@ class ServiceForm(ModelForm):
def __init__(self, *args, **kwargs):
prefix = kwargs.pop('prefix', self.Meta.model.__name__)
super(ServiceForm, self).__init__(*args, prefix=prefix, **kwargs)
self.fields['servers'].queryset = Interface.objects.all()\
.select_related('domain__extension')
def save(self, commit=True):
instance = super(ServiceForm, self).save(commit=False)

View file

@ -1056,7 +1056,9 @@ def history(request, object, id):
@login_required
@permission_required('cableur')
def index_portlist(request):
port_list = OuverturePortList.objects.prefetch_related('ouvertureport_set').prefetch_related('interface_set__domain__extension').prefetch_related('interface_set__machine__user').order_by('name')
port_list = OuverturePortList.objects.prefetch_related('ouvertureport_set')\
.prefetch_related('interface_set__domain__extension')\
.prefetch_related('interface_set__machine__user').order_by('name')
return render(request, "machines/index_portlist.html", {'port_list':port_list})
@login_required