aboutsummaryrefslogtreecommitdiff
path: root/models.py
diff options
context:
space:
mode:
Diffstat (limited to 'models.py')
-rw-r--r--models.py16
1 files changed, 14 insertions, 2 deletions
diff --git a/models.py b/models.py
index 6bb9733..c263510 100644
--- a/models.py
+++ b/models.py
@@ -21,7 +21,19 @@ from django.utils.text import slugify
from .utils import parse_group
-class Year(models.Model):
+class SlugModel(models.Model):
+ def save(self):
+ if not self.slug:
+ self.slug = slugify(self.name)
+
+ super(SlugModel, self).save()
+
+
+ class Meta:
+ abstract = True
+
+
+class Year(SlugModel):
name = models.CharField(max_length=16, verbose_name="année")
slug = models.SlugField(max_length=16, unique=True, default="")
@@ -34,7 +46,7 @@ class Year(models.Model):
verbose_name_plural = "années"
-class Timetable(models.Model):
+class Timetable(SlugModel):
year = models.ForeignKey(Year, on_delete=models.CASCADE, verbose_name="année")
name = models.CharField(max_length=64, verbose_name="nom")
url = models.URLField(max_length=255, verbose_name="URL")