From 76e22268010919e4b7691229529eb99c7cea390b Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Wed, 18 Oct 2017 04:11:27 +0200 Subject: [PATCH] Fix et optimisation select_related --- cotisations/views.py | 3 ++- machines/forms.py | 2 ++ machines/views.py | 4 +++- 3 files changed, 7 insertions(+), 2 deletions(-) diff --git a/cotisations/views.py b/cotisations/views.py index fc4469aa..4e2c5304 100644 --- a/cotisations/views.py +++ b/cotisations/views.py @@ -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) diff --git a/machines/forms.py b/machines/forms.py index 9820fbdc..0086c3d6 100644 --- a/machines/forms.py +++ b/machines/forms.py @@ -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) diff --git a/machines/views.py b/machines/views.py index dc3e0406..85c19dde 100644 --- a/machines/views.py +++ b/machines/views.py @@ -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