From f2717d6a04d5c463a5b5e8aa41001c0589d3b4c5 Mon Sep 17 00:00:00 2001 From: Alban Gruin Date: Mon, 23 Jan 2017 09:13:25 +0100 Subject: Amélioration des clés des modèles --- models.py | 13 +++++++------ 1 file changed, 7 insertions(+), 6 deletions(-) diff --git a/models.py b/models.py index 7d5efd7..18e0246 100644 --- a/models.py +++ b/models.py @@ -37,10 +37,10 @@ class Group(models.Model): name = models.CharField(max_length=255, verbose_name="nom") timetable = models.ForeignKey(Timetable, on_delete=models.CASCADE, verbose_name="emploi du temps") - mention = models.CharField(max_length=32, db_index=True) - subgroup = models.CharField(max_length=1, verbose_name="sous-groupe", db_index=True) - td = models.IntegerField(verbose_name="groupe de TD", null=True, db_index=True) - tp = models.IntegerField(verbose_name="groupe de TP", null=True, db_index=True) + mention = models.CharField(max_length=32) + subgroup = models.CharField(max_length=1, verbose_name="sous-groupe") + td = models.IntegerField(verbose_name="groupe de TD", null=True) + tp = models.IntegerField(verbose_name="groupe de TP", null=True) slug = models.SlugField(max_length=64, unique=True, default="") @@ -67,7 +67,9 @@ class Group(models.Model): class Meta: + index_together = ("mention", "subgroup", "td", "tp",) unique_together = ("name", "timetable",) + verbose_name = "groupe" verbose_name_plural = "groupes" @@ -75,7 +77,7 @@ class Group(models.Model): class Subscription(models.Model): email = models.EmailField(verbose_name="adresse") group = models.ForeignKey(Group, on_delete=models.CASCADE, verbose_name="groupe") - active = models.BooleanField(verbose_name="activé", default=False) + active = models.BooleanField(verbose_name="activé", default=False, db_index=True) token = models.CharField(max_length=64, unique=True, default="") def save(self): @@ -85,7 +87,6 @@ class Subscription(models.Model): class Meta: - index_together = ("group", "active",) unique_together = ("email", "group",) verbose_name = "abonnement" verbose_name_plural = "abonnements" -- cgit v1.2.1