From 1561cb829a48d49d36242db89fa4490144767065 Mon Sep 17 00:00:00 2001 From: Alban Gruin Date: Thu, 7 Sep 2017 17:02:27 +0200 Subject: Séparation de l’année et de la mention dans le modèle Timetable --- admin.py | 4 ++-- models.py | 10 ++++++++-- 2 files changed, 10 insertions(+), 4 deletions(-) diff --git a/admin.py b/admin.py index 2408623..ca2fed9 100644 --- a/admin.py +++ b/admin.py @@ -20,8 +20,8 @@ from .models import Timetable, LastUpdate, Group, Subscription, Room, Course @admin.register(Timetable) class TimetableAdmin(admin.ModelAdmin): - prepopulated_fields = {"slug": ("name",)} - list_display = ("name", "url",) + prepopulated_fields = {"slug": ("year", "name",)} + list_display = ("full_name", "url",) @admin.register(LastUpdate) diff --git a/models.py b/models.py index 0b0ee63..61e7f6c 100644 --- a/models.py +++ b/models.py @@ -26,15 +26,21 @@ import os class Timetable(models.Model): - name = models.CharField(max_length=64, unique=True, verbose_name="nom") + year = models.CharField(max_length=16, verbose_name="année") + name = models.CharField(max_length=64, 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 + return self.full_name() + + def full_name(self): + return self.year + " " + self.name + full_name.short_description = "Nom complet" class Meta: + unique_together = ("year", "name",) verbose_name = "emploi du temps" verbose_name_plural = "emplois du temps" -- cgit v1.2.1