Select the election
This commit is contained in:
parent
7c6dfa1073
commit
f4a2d1fb10
1 changed files with 13 additions and 1 deletions
|
@ -4,7 +4,19 @@ from django.views.generic.detail import SingleObjectMixin
|
||||||
from .models import Election, Option, Question
|
from .models import Election, Option, Question
|
||||||
|
|
||||||
|
|
||||||
class RestrictAccessMixin:
|
class SelectElectionMixin:
|
||||||
|
"""Sélectionne automatiquement les foreignkeys voulues"""
|
||||||
|
|
||||||
|
def get_queryset(self):
|
||||||
|
qs = super().get_queryset()
|
||||||
|
if self.model is Question:
|
||||||
|
return qs.select_related("election")
|
||||||
|
elif self.model is Option:
|
||||||
|
return qs.select_related("question__election")
|
||||||
|
return qs
|
||||||
|
|
||||||
|
|
||||||
|
class RestrictAccessMixin(SelectElectionMixin):
|
||||||
"""Permet de restreindre l'accès à des élections/questions/options"""
|
"""Permet de restreindre l'accès à des élections/questions/options"""
|
||||||
|
|
||||||
f_prefixes = {Election: "", Question: "election__", Option: "question__election__"}
|
f_prefixes = {Election: "", Question: "election__", Option: "question__election__"}
|
||||||
|
|
Loading…
Reference in a new issue