Utilise select_related

This commit is contained in:
Tom Hubrecht 2021-04-17 01:25:29 +02:00
parent 3ecea69d2c
commit 875b80b2a6

View file

@ -278,7 +278,7 @@ class BallotsData:
"""Renvoie un tableau affichant les options sélectionnées pour chaque bulletin"""
from .models import Vote
votes = Vote.objects.filter(option__question=question)
votes = Vote.objects.filter(option__question=question).select_related("user")
options = list(question.options.all())
@ -298,7 +298,9 @@ class BallotsData:
from .models import Rank
options = list(question.options.all())
ranks = Rank.objects.select_related("vote").filter(vote__option__in=options)
ranks = Rank.objects.select_related("vote__user").filter(
vote__option__in=options
)
ranks_by_user = {}
for r in ranks: