diff options
Diffstat (limited to 'models.py')
-rw-r--r-- | models.py | 19 |
1 files changed, 19 insertions, 0 deletions
@@ -19,9 +19,28 @@ 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) + 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) + def __str__(self): return self.name + def save(self): + parts = self.name.split("-")[-2:] + group = parts[1].strip()[2:] + + self.mention = parts[0].strip() + self.subgroup = group[0] + + if len(group) > 1: + self.td = int(group[1]) + if len(group) > 2: + self.tp = int(group[2]) + + super(Group, self).save() + class Meta: verbose_name = "groupe" |