Compare commits

...

2 commits

View file

@ -4,7 +4,7 @@ from datetime import timedelta
from django.contrib.auth import get_user_model from django.contrib.auth import get_user_model
from django.contrib.auth.mixins import PermissionRequiredMixin from django.contrib.auth.mixins import PermissionRequiredMixin
from django.db.models import Q, Max from django.db.models import Q, Max, prefetch_related_objects
from django.http import Http404 from django.http import Http404
from django.urls import reverse, reverse_lazy from django.urls import reverse, reverse_lazy
from django.utils import timezone from django.utils import timezone
@ -88,7 +88,13 @@ class RaidDetailView(SingleObjectMixin, MultiModelFormView):
def get_queryset(self): def get_queryset(self):
return Raid.objects.prefetch_related( return Raid.objects.prefetch_related(
"responses", "responses__character", "comments", "comments__user__main" "responses",
"responses__character",
"responses__character__user",
"responses__character__user__rank",
"responses__character__user__main",
"comments",
"comments__user__main"
).all() ).all()
def get_form_classes(self): def get_form_classes(self):
@ -138,6 +144,7 @@ class RaidDetailView(SingleObjectMixin, MultiModelFormView):
.order_by("main__klass") .order_by("main__klass")
pseudo_no_responses = [RaidResponse(character=user.main, status=None) pseudo_no_responses = [RaidResponse(character=user.main, status=None)
for user in no_response_users] for user in no_response_users]
prefetch_related_objects(pseudo_no_responses, "character__user__rank", "character__user__main")
context["responses"] = list(raid.responses.all()) + pseudo_no_responses context["responses"] = list(raid.responses.all()) + pseudo_no_responses
return context return context