From f700d59e65b118b061ef39d2c22f5974e1f6292b Mon Sep 17 00:00:00 2001 From: Gabriel Detraz Date: Sat, 27 May 2017 04:55:33 +0200 Subject: [PATCH] Optimisations select_related --- machines/views.py | 8 ++++---- users/models.py | 2 +- users/views.py | 4 ++-- 3 files changed, 7 insertions(+), 7 deletions(-) diff --git a/machines/views.py b/machines/views.py index 7b1af78a..b0f3eb27 100644 --- a/machines/views.py +++ b/machines/views.py @@ -625,21 +625,21 @@ def index(request): @login_required @permission_required('cableur') def index_iptype(request): - iptype_list = IpType.objects.order_by('type') + iptype_list = IpType.objects.select_related('extension').order_by('type') return render(request, 'machines/index_iptype.html', {'iptype_list':iptype_list}) @login_required @permission_required('cableur') def index_machinetype(request): - machinetype_list = MachineType.objects.order_by('type') + machinetype_list = MachineType.objects.select_related('ip_type').order_by('type') return render(request, 'machines/index_machinetype.html', {'machinetype_list':machinetype_list}) @login_required @permission_required('cableur') def index_extension(request): extension_list = Extension.objects.order_by('name') - mx_list = Mx.objects.order_by('zone') - ns_list = Ns.objects.order_by('zone') + mx_list = Mx.objects.order_by('zone').select_related('zone') + ns_list = Ns.objects.order_by('zone').select_related('zone') return render(request, 'machines/index_extension.html', {'extension_list':extension_list, 'mx_list': mx_list, 'ns_list': ns_list}) @login_required diff --git a/users/models.py b/users/models.py index ee4394df..f720f8d6 100644 --- a/users/models.py +++ b/users/models.py @@ -696,7 +696,7 @@ class NewListRightForm(ListRightForm): self.fields['gid'].label = 'Gid, attention, cet attribut ne doit pas être modifié après création' class DelListRightForm(ModelForm): - listrights = forms.ModelMultipleChoiceField(queryset=ListRight.objects.all(), label="Droits actuels", widget=forms.CheckboxSelectMultiple) + listrights = forms.ModelMultipleChoiceField(queryset=ListRight.objects.all().select_related('user'), label="Droits actuels", widget=forms.CheckboxSelectMultiple) class Meta: exclude = ['listright','gid'] diff --git a/users/views.py b/users/views.py index 11edd4bc..a0efc9ae 100644 --- a/users/views.py +++ b/users/views.py @@ -496,7 +496,7 @@ def index(request): @permission_required('cableur') def index_ban(request): """ Affiche l'ensemble des ban, need droit cableur """ - ban_list = Ban.objects.order_by('date_start').reverse() + ban_list = Ban.objects.order_by('date_start').select_related('user').reverse() paginator = Paginator(ban_list, PAGINATION_NUMBER) page = request.GET.get('page') try: @@ -513,7 +513,7 @@ def index_ban(request): @permission_required('cableur') def index_white(request): """ Affiche l'ensemble des whitelist, need droit cableur """ - white_list = Whitelist.objects.order_by('date_start') + white_list = Whitelist.objects.select_related('user').order_by('date_start') return render( request, 'users/index_whitelist.html',