From 5349208724305c9ec1ea4ab1c51af9969dc586e0 Mon Sep 17 00:00:00 2001 From: Alban Gruin Date: Fri, 20 Jan 2017 14:37:31 +0100 Subject: Changement du gestionnaire des cours --- models.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/models.py b/models.py index 743ef03..13ae3f4 100644 --- a/models.py +++ b/models.py @@ -1,4 +1,5 @@ from django.db import models +from django.db.models import Q from django.utils.text import slugify @@ -67,7 +68,14 @@ class Room(models.Model): verbose_name_plural = "salles" +class CourseManager(models.Manager): + def get_courses_for_group(self, group, **filters): + return self.get_queryset().filter(Q(groups__td__isnull=True) | Q(groups__td=group.td), Q(groups__tp__isnull=True) | Q(groups__tp=group.tp), groups__mention=group.mention, groups__subgroup=group.subgroup, **filters).order_by("begin") + + class Course(models.Model): + objects = CourseManager() + name = models.CharField(max_length=255, verbose_name="nom", null=True) type_ = models.CharField(name="type", max_length=255, verbose_name="type de cours", null=True) timetable = models.ForeignKey(Timetable, on_delete=models.CASCADE, verbose_name="emploi du temps") -- cgit v1.2.1