From ccd38d2723fb63184df979af6d66306a54d8e0a0 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Martin=20P=C3=A9pin?= Date: Tue, 7 Jun 2016 22:49:19 +0200 Subject: [PATCH] Remplace `filter` par `_set` quand c'est possible Par exemple `Spectacle.objects.filter(tirage=tirage)` devient `tirage.spectacle_set` --- bda/views.py | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/bda/views.py b/bda/views.py index 7d97ca0f..624f0a3b 100644 --- a/bda/views.py +++ b/bda/views.py @@ -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",