aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorAlban Gruin2017-01-19 14:27:02 +0100
committerAlban Gruin2017-01-19 14:27:02 +0100
commitd5707a7293d68eb064f9e407531d7f1817b3c6dd (patch)
tree4033f9b77ce1eca88e143f3836abf65d105bdcca
parente9d4b61b1fb0d5efa78df56a2529185d3d8fabf5 (diff)
Détermination automatique des mentions, sous-groupes, groupe de td et tp
-rw-r--r--admin.py2
-rw-r--r--models.py19
2 files changed, 21 insertions, 0 deletions
diff --git a/admin.py b/admin.py
index bdf59a2..5583967 100644
--- a/admin.py
+++ b/admin.py
@@ -10,6 +10,8 @@ class TimetableAdmin(admin.ModelAdmin):
@admin.register(Group)
class GroupAdmin(admin.ModelAdmin):
+ fieldsets = (
+ (None, {"fields": ("name", "timetable",)}),)
list_display = ("name", "timetable",)
list_filter = ("timetable__name",)
diff --git a/models.py b/models.py
index 09bf876..93d5e27 100644
--- a/models.py
+++ b/models.py
@@ -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"