Fewer requests on accounts groups.

- Saves two queries.

(4 prefetch where done, replaced by 2 prefetchs (whose 1 with 2
selected_related))
This commit is contained in:
Aurélien Delobelle 2017-04-06 19:25:23 +02:00
parent afdb08b424
commit 2731d4630f

View file

@ -518,13 +518,22 @@ def account_update(request, trigramme):
'pwd_form': pwd_form,
})
@permission_required('kfet.manage_perms')
def account_group(request):
groups = (Group.objects
.filter(name__icontains='K-Fêt')
.prefetch_related('permissions', 'user_set__profile__account_kfet')
user_pre = Prefetch(
'user_set',
queryset=User.objects.select_related('profile__account_kfet'),
)
return render(request, 'kfet/account_group.html', { 'groups': groups })
groups = (
Group.objects
.filter(name__icontains='K-Fêt')
.prefetch_related('permissions', user_pre)
)
return render(request, 'kfet/account_group.html', {
'groups': groups,
})
class AccountGroupCreate(SuccessMessageMixin, CreateView):
model = Group