Filtre les participants dans la requête SQL

Et non plus en python
This commit is contained in:
Martin Pépin 2016-06-22 02:29:20 +02:00
parent fc98056582
commit 24e88a95a3

View file

@ -5,6 +5,7 @@ from __future__ import division
from django.shortcuts import render, get_object_or_404
from django.contrib.auth.decorators import login_required
from django.db import models
from django.db.models import Count
from django.core import serializers
from django.forms.models import inlineformset_factory
import hashlib
@ -329,9 +330,10 @@ class SpectacleListView(ListView):
@buro_required
def unpaid(request, tirage_id):
tirage = get_object_or_404(Tirage, id=tirage_id)
unpaid = tirage.participant_set.filter(paid=False).all()
really_unpaid = [part for part in unpaid if part.attribution_set.all()]
return render(request, "bda-unpaid.html", {"unpaid": really_unpaid})
unpaid = tirage.participant_set \
.annotate(nb_attributions=Count('attribution')) \
.filter(paid=False, nb_attributions__gt=0).all()
return render(request, "bda-unpaid.html", {"unpaid": unpaid})
@buro_required
def liste_spectacles_ics(request, tirage_id):