From 1b0fbf29a484b16de31ac5df1b3fded39be95e97 Mon Sep 17 00:00:00 2001 From: Alban Gruin Date: Fri, 17 Nov 2017 21:20:37 +0100 Subject: Ajout d’un champ slug au modèle des salles --- admin.py | 2 +- models.py | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/admin.py b/admin.py index 7739a95..011ad73 100644 --- a/admin.py +++ b/admin.py @@ -55,7 +55,7 @@ class GroupAdmin(admin.ModelAdmin): @admin.register(Room) class RoomAdmin(admin.ModelAdmin): - pass + prepopulated_fields = {"slug": ("name",)} @admin.register(Course) diff --git a/models.py b/models.py index 035bd6d..547c0e1 100644 --- a/models.py +++ b/models.py @@ -142,10 +142,14 @@ class Group(models.Model): class Room(models.Model): name = models.CharField(max_length=255, unique=True, verbose_name="nom") + slug = models.SlugField(max_length=64, default="", unique=True) def __str__(self): return self.name + def save(self, *args, **kwargs): + self.slug = slugify(self.name) + super(Room, self).save() class Meta: verbose_name = "salle" -- cgit v1.2.1