From dc5618c3b3af18a5f6e1d50844097c745317125a Mon Sep 17 00:00:00 2001 From: Alban Gruin Date: Sun, 24 Sep 2017 17:36:40 +0200 Subject: Ajout de la date et de l’heure automatiquement lors de la création d’un cours --- management/commands/timetables.py | 5 ++--- models.py | 2 +- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/management/commands/timetables.py b/management/commands/timetables.py index 45a57ee..0716a91 100644 --- a/management/commands/timetables.py +++ b/management/commands/timetables.py @@ -15,6 +15,7 @@ from django.core.management.base import BaseCommand from django.db import transaction +from django.db.models import Max from django.utils import timezone from edt.models import Timetable, Course @@ -27,9 +28,8 @@ import datetime def process_timetable_week(timetable, year, week, soup, weeks_in_soup): begin, end = get_weeks(year, week) - last_update_date = Course.objects.filter(begin__gte=start, begin__lt=end).aggregate(Max("last_update"))["last_update__max"] + last_update_date = Course.objects.filter(begin__gte=begin, begin__lt=end).aggregate(Max("last_update"))["last_update__max"] new_update_date = get_update_date(soup) - updated_at = timezone.make_aware(datetime.datetime.now()) if last_update_date is not None and new_update_date is not None and \ last_update_date >= new_update_date: @@ -42,7 +42,6 @@ def process_timetable_week(timetable, year, week, soup, weeks_in_soup): course.name = name course.type = type_ course.notes = notes - course.updated_at = updated_at course.groups.add(*groups) if rooms is not None: diff --git a/models.py b/models.py index 5128c8a..e284c28 100644 --- a/models.py +++ b/models.py @@ -143,7 +143,7 @@ class Course(models.Model): begin = models.DateTimeField(verbose_name="début du cours", db_index=True) end = models.DateTimeField(verbose_name="fin du cours") - last_update = models.DateTimeField(verbose_name="dernière mise à jour") + last_update = models.DateTimeField(verbose_name="dernière mise à jour", auto_now_add=True) def __str__(self): return self.name -- cgit v1.2.1