From fb6ea65e7d32dcf3d697e6c63985a018ada4d6b1 Mon Sep 17 00:00:00 2001 From: Alban Gruin Date: Mon, 27 Nov 2017 16:37:31 +0100 Subject: Ajout d’un gestionnaire pour Timetable récupérant automatiquement les années Réduit considérablement le nombre d’appels effectués dans l’interface d’administration --- models.py | 7 +++++++ views.py | 2 +- 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/models.py b/models.py index 6124b59..b8c67d6 100644 --- a/models.py +++ b/models.py @@ -62,7 +62,14 @@ class Source(models.Model): verbose_name_plural = "sources d’emploi du temps" +class TimetableManager(Manager): + def get_queryset(self): + return super(Manager, self).get_queryset().select_related("year") + + class Timetable(SlugModel): + objects = TimetableManager() + year = models.ForeignKey(Year, on_delete=models.CASCADE, verbose_name="année") name = models.CharField(max_length=64, verbose_name="nom") diff --git a/views.py b/views.py index 2bf596b..97a1d28 100644 --- a/views.py +++ b/views.py @@ -31,7 +31,7 @@ def index(request): def mention_list(request, year_slug): year = get_object_or_404(Year, slug=year_slug) - timetables = Timetable.objects.order_by("name").filter(year=year).select_related("year") + timetables = Timetable.objects.order_by("name").filter(year=year) return render(request, "index.html", {"year": year, "elements": timetables}) -- cgit v1.2.1