From 1cd70228b91c2b38b412e7e4797c751235c30488 Mon Sep 17 00:00:00 2001 From: moanos Date: Tue, 29 Oct 2024 17:50:29 +0100 Subject: [PATCH] fix: Use timezone data not native datetime --- ...lter_adoptionnotice_created_at_and_more.py | 24 +++++++++++++++++++ src/fellchensammlung/tasks.py | 6 ++--- 2 files changed, 27 insertions(+), 3 deletions(-) create mode 100644 src/fellchensammlung/migrations/0011_alter_adoptionnotice_created_at_and_more.py diff --git a/src/fellchensammlung/migrations/0011_alter_adoptionnotice_created_at_and_more.py b/src/fellchensammlung/migrations/0011_alter_adoptionnotice_created_at_and_more.py new file mode 100644 index 0000000..9652dea --- /dev/null +++ b/src/fellchensammlung/migrations/0011_alter_adoptionnotice_created_at_and_more.py @@ -0,0 +1,24 @@ +# Generated by Django 5.1.1 on 2024-10-29 10:44 + +import django.utils.timezone +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('fellchensammlung', '0010_timestamp'), + ] + + operations = [ + migrations.AlterField( + model_name='adoptionnotice', + name='created_at', + field=models.DateField(default=django.utils.timezone.now, verbose_name='Erstellt am'), + ), + migrations.AlterField( + model_name='adoptionnotice', + name='last_checked', + field=models.DateTimeField(default=django.utils.timezone.now, verbose_name='Zuletzt überprüft am'), + ), + ] diff --git a/src/fellchensammlung/tasks.py b/src/fellchensammlung/tasks.py index 2731609..763ab38 100644 --- a/src/fellchensammlung/tasks.py +++ b/src/fellchensammlung/tasks.py @@ -1,4 +1,4 @@ -from datetime import datetime +from django.utils import timezone from notfellchen.celery import app as celery_app from .tools.admin import clean_locations, deactivate_unchecked_adoption_notices from .tools.misc import healthcheck_ok @@ -8,9 +8,9 @@ from .models import Location, AdoptionNotice, Timestamp def set_timestamp(key: str): try: ts = Timestamp.objects.get(key=key) - ts.timestamp = datetime.now() + ts.timestamp = timezone.now() except Timestamp.DoesNotExist: - Timestamp.objects.create(key=key, timestamp=datetime.now()) + Timestamp.objects.create(key=key, timestamp=timezone.now()) @celery_app.task(name="admin.clean_locations")