Fewer requests on unpaid view

This commit is contained in:
Aurélien Delobelle 2017-04-08 13:08:53 +02:00
parent 15d2faf8e1
commit 98f355ed20

View file

@ -670,9 +670,12 @@ class SpectacleListView(ListView):
@buro_required @buro_required
def unpaid(request, tirage_id): def unpaid(request, tirage_id):
tirage = get_object_or_404(Tirage, id=tirage_id) tirage = get_object_or_404(Tirage, id=tirage_id)
unpaid = tirage.participant_set \ unpaid = (
.annotate(nb_attributions=Count('attribution')) \ tirage.participant_set
.filter(paid=False, nb_attributions__gt=0).all() .annotate(nb_attributions=Count('attribution'))
.filter(paid=False, nb_attributions__gt=0)
.select_related('user')
)
return render(request, "bda-unpaid.html", {"unpaid": unpaid}) return render(request, "bda-unpaid.html", {"unpaid": unpaid})