aboutsummaryrefslogtreecommitdiff
path: root/models.py
diff options
context:
space:
mode:
authorAlban Gruin2017-09-08 12:58:04 +0200
committerAlban Gruin2017-09-08 12:58:04 +0200
commitaf0fe7024ce13cdb30170f00df8a1883eef23bf8 (patch)
treede2f0a5a327dc441f6e9e552e8472fbc93f88f1b /models.py
parentb769b34de15ab37d7d97078a72045eb49d46036b (diff)
Changement des index du modèle Timetable, meilleure utilisation des requêtes
Diffstat (limited to 'models.py')
-rw-r--r--models.py15
1 files changed, 8 insertions, 7 deletions
diff --git a/models.py b/models.py
index 3e8eae3..109b327 100644
--- a/models.py
+++ b/models.py
@@ -39,15 +39,16 @@ class Year(models.Model):
class Timetable(models.Model):
year = models.ForeignKey(Year, verbose_name="année")
- name = models.CharField(max_length=64, unique=True, verbose_name="nom")
- url = models.URLField(max_length=255, unique=True, verbose_name="URL")
- slug = models.SlugField(max_length=64, unique=True, default="")
+ name = models.CharField(max_length=64, verbose_name="nom")
+ url = models.URLField(max_length=255, verbose_name="URL")
+ slug = models.SlugField(max_length=64, default="")
def __str__(self):
return self.year.name + " " + self.name
class Meta:
+ unique_together = (("year", "name"), ("year", "slug"),)
verbose_name = "emploi du temps"
verbose_name_plural = "emplois du temps"
@@ -71,8 +72,8 @@ class LastUpdate(models.Model):
class GroupManager(Manager):
- def get_relevant_groups(self, *args, **filters):
- return self.get_queryset().filter(*args, **filters).annotate(children_count=Count("children")).filter(children_count=0)
+ def get_relevant_groups(self, *args, **criteria):
+ return self.get_queryset().filter(*args, **criteria).annotate(children_count=Count("children")).filter(children_count=0)
class Group(models.Model):
@@ -151,8 +152,8 @@ class Room(models.Model):
class CourseManager(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), Q(groups__subgroup__isnull=True) | Q(groups__subgroup=group.subgroup), groups__mention=group.mention, timetable=group.timetable, **filters).order_by("begin")
+ def get_courses_for_group(self, group, **criteria):
+ 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), Q(groups__subgroup__isnull=True) | Q(groups__subgroup=group.subgroup), groups__mention=group.mention, timetable=group.timetable, **criteria).order_by("begin")
def get_weeks(self, **criteria):
return self.get_queryset().filter(**criteria).order_by("groups__name", "year", "week").annotate(_=Count(("groups", "year", "week", "begin")), year=ExtractYear("begin"), week=ExtractWeek("begin"))