From 582b1d2be865cc0fba9aa4726404f4370d0b80c5 Mon Sep 17 00:00:00 2001 From: Alban Gruin Date: Sun, 19 Nov 2017 01:10:29 +0100 Subject: Séparation en deux modèles des emplois du temps : un pour l’affichage, l’autre pour les sources --- admin.py | 9 +++++++-- models.py | 22 +++++++++++++++++----- 2 files changed, 24 insertions(+), 7 deletions(-) diff --git a/admin.py b/admin.py index 011ad73..717a386 100644 --- a/admin.py +++ b/admin.py @@ -14,7 +14,7 @@ # along with celcatsanitizer. If not, see . from django.contrib import admin -from .models import Timetable, Group, Room, Course, Year +from .models import Course, Group, Room, Timetable, TimetableFront, Year def make_hidden(modeladmin, request, queryset): queryset.update(hidden=True) @@ -34,8 +34,13 @@ class YearAdmin(admin.ModelAdmin): @admin.register(Timetable) class TimetableAdmin(admin.ModelAdmin): + list_display = ("url", "last_update_date",) + + +@admin.register(TimetableFront) +class TimetableFrontAdmin(admin.ModelAdmin): prepopulated_fields = {"slug": ("name",)} - list_display = ("name", "year", "url",) + list_display = ("name", "year", "source",) list_filter = ("year__name",) ordering = ("year", "name",) diff --git a/models.py b/models.py index 66d5ae5..dc9732b 100644 --- a/models.py +++ b/models.py @@ -49,15 +49,27 @@ class Year(SlugModel): verbose_name_plural = "années" -class Timetable(SlugModel): +class Timetable(models.Model): + url = models.URLField(max_length=255, verbose_name="URL", unique=True) + last_update_date = models.DateTimeField(verbose_name="dernière mise à jour Celcat", + null=True, blank=True) + + def __str__(self): + return self.url + + + class Meta: + verbose_name = "source d’emploi du temps" + verbose_name_plural = "sources d’emploi du temps" + + +class TimetableFront(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") slug = models.SlugField(max_length=64, default="") - - last_update_date = models.DateTimeField(verbose_name="dernière mise à jour Celcat", - null=True, blank=True) + source = models.ForeignKey(Timetable, on_delete=models.CASCADE, + verbose_name="source") def __str__(self): return self.year.name + " " + self.name -- cgit v1.2.1