Remplace filter par _set quand c'est possible

Par exemple
`Spectacle.objects.filter(tirage=tirage)` devient
`tirage.spectacle_set`
This commit is contained in:
Martin Pépin 2016-06-07 22:49:19 +02:00
parent 688dce33d5
commit ccd38d2723

View file

@ -38,7 +38,7 @@ def etat_places(request, tirage_id):
.all() \
.values('spectacle','spectacle__title') \
.annotate(total=models.Count('spectacle'))
spectacles = Spectacle.objects.filter(tirage=tirage).all()
spectacles = tirage.spectacle_set.all()
spectacles_dict = {}
total = 0
for spectacle in spectacles:
@ -142,7 +142,7 @@ def inscription(request, tirage_id):
"choices": choices})
def formfield_callback(f, **kwargs):
if f.name == "spectacle":
kwargs['queryset'] = Spectacle.objects.filter(tirage=tirage)
kwargs['queryset'] = tirage.spectacle_set
return f.formfield(**kwargs)
BdaFormSet = inlineformset_factory(
Participant,
@ -189,8 +189,8 @@ def do_tirage(request, tirage_id):
tirage_elt.save()
start = time.time()
data = {}
shows = Spectacle.objects.filter(tirage=tirage_elt).select_related().all()
members = Participant.objects.filter(tirage=tirage_elt).all()
shows = tirage_elt.spectacle_set.select_related().all()
members = tirage_elt.spectacle_set.all()
choices = ChoixSpectacle.objects.filter(spectacle__tirage=tirage_elt).order_by(
'participant', 'priority').select_related().all()
algo = Algorithm(shows, members, choices)
@ -324,13 +324,13 @@ class SpectacleListView(ListView):
@buro_required
def unpaid(request, tirage_id):
tirage = get_object_or_404(Tirage, id=tirage_id)
unpaid = Participant.objects.filter(tirage=tirage, paid=False).all()
unpaid = tirage.participant_set.filter(paid=False).all()
return render(request, "bda-unpaid.html", {"unpaid": unpaid})
@buro_required
def liste_spectacles_ics(request, tirage_id):
tirage = get_object_or_404(Tirage, id=tirage_id)
spectacles = Spectacle.objects.filter(tirage=tirage).order_by("date").all()
spectacles = tirage.spectacle_set.order_by("date").all()
for spectacle in spectacles:
spectacle.dtend = spectacle.date + timedelta(seconds=7200)
return render(request, "liste_spectacles.ics",