forked from DGNum/gestioCOF
Fewer db accesses on transfers list view.
- Add select_related for `from_acc`, `to_acc` and `group.valid_by`. - 2 requests instead of (3 * #transfers)
This commit is contained in:
parent
709d421b2c
commit
f8b71b604c
1 changed files with 16 additions and 3 deletions
|
@ -1477,19 +1477,32 @@ class SettingsUpdate(SuccessMessageMixin, UpdateView):
|
||||||
Settings.empty_cache()
|
Settings.empty_cache()
|
||||||
return super(SettingsUpdate, self).form_valid(form)
|
return super(SettingsUpdate, self).form_valid(form)
|
||||||
|
|
||||||
|
|
||||||
# -----
|
# -----
|
||||||
# Transfer views
|
# Transfer views
|
||||||
# -----
|
# -----
|
||||||
|
|
||||||
@teamkfet_required
|
@teamkfet_required
|
||||||
def transfers(request):
|
def transfers(request):
|
||||||
transfergroups = (TransferGroup.objects
|
transfers_pre = Prefetch(
|
||||||
.prefetch_related('transfers')
|
'transfers',
|
||||||
.order_by('-at'))
|
queryset=(
|
||||||
|
Transfer.objects
|
||||||
|
.select_related('from_acc', 'to_acc')
|
||||||
|
),
|
||||||
|
)
|
||||||
|
|
||||||
|
transfergroups = (
|
||||||
|
TransferGroup.objects
|
||||||
|
.select_related('valid_by')
|
||||||
|
.prefetch_related(transfers_pre)
|
||||||
|
.order_by('-at')
|
||||||
|
)
|
||||||
return render(request, 'kfet/transfers.html', {
|
return render(request, 'kfet/transfers.html', {
|
||||||
'transfergroups': transfergroups,
|
'transfergroups': transfergroups,
|
||||||
})
|
})
|
||||||
|
|
||||||
|
|
||||||
@teamkfet_required
|
@teamkfet_required
|
||||||
def transfers_create(request):
|
def transfers_create(request):
|
||||||
transfer_formset = TransferFormSet(queryset=Transfer.objects.none())
|
transfer_formset = TransferFormSet(queryset=Transfer.objects.none())
|
||||||
|
|
Loading…
Reference in a new issue