From 84ab4542792b089bf0dbca98b88ba688b3f1d263 Mon Sep 17 00:00:00 2001 From: Birger Schacht Date: Tue, 16 Apr 2024 21:39:41 +0200 Subject: [PATCH] fix(history): make history timezone aware Closes: #789 --- apis_core/history/models.py | 3 ++- apis_core/history/views.py | 3 ++- 2 files changed, 4 insertions(+), 2 deletions(-) diff --git a/apis_core/history/models.py b/apis_core/history/models.py index 366fce3fa..46740ceda 100644 --- a/apis_core/history/models.py +++ b/apis_core/history/models.py @@ -11,6 +11,7 @@ from django.db.models import UniqueConstraint, Q from django.db.models.functions import Lower from django.contrib.contenttypes.models import ContentType +from django.utils import timezone class APISHistoricalRecords(HistoricalRecords, GenericModel): @@ -122,7 +123,7 @@ class Meta: def save(self, *args, **kwargs) -> None: if self._history_date is None: - self._history_date = datetime.now() + self._history_date = timezone.now() return super().save(*args, **kwargs) def delete(self, *args, **kwargs) -> tuple[int, dict[str, int]]: diff --git a/apis_core/history/views.py b/apis_core/history/views.py index 9b7c122c2..369b85d0e 100644 --- a/apis_core/history/views.py +++ b/apis_core/history/views.py @@ -5,6 +5,7 @@ from django.contrib.contenttypes.models import ContentType from datetime import datetime from django.views.generic.detail import SingleObjectMixin +from django.utils import timezone def convert_timestamps(data): @@ -51,7 +52,7 @@ def create_new_version(request, contenttype, pk): ) ] history_latest.history_id = None - history_latest.history_date = datetime.now() + history_latest.history_date = timezone.now() history_latest.save() if latest_version_list: latest_version = max(latest_version_list)