1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
|
from django.db import models
class Timetable(models.Model):
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="")
def __str__(self):
return self.name
class Meta:
verbose_name = "emploi du temps"
verbose_name_plural = "emplois du temps"
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"
verbose_name_plural = "groupes"
unique_together = ("name", "timetable",)
class Room(models.Model):
name = models.CharField(max_length=255, unique=True, verbose_name="nom")
def __str__(self):
return self.name
class Meta:
verbose_name = "salle"
verbose_name_plural = "salles"
class Course(models.Model):
name = models.CharField(max_length=255, verbose_name="nom")
type_ = models.CharField(name="type", max_length=255, verbose_name="type de cours")
timetable = models.ForeignKey(Timetable, on_delete=models.CASCADE, verbose_name="emploi du temps")
groups = models.ManyToManyField(Group, verbose_name="groupes")
rooms = models.ManyToManyField(Room, verbose_name="salles")
begin = models.DateTimeField(verbose_name="début du cours")
end = models.DateTimeField(verbose_name="fin du cours")
def __str__(self):
return self.name
class Meta:
verbose_name = "cours"
verbose_name_plural = "cours"
|