From 495dd6444f641c2a57efa3c66700134e09b7a905 Mon Sep 17 00:00:00 2001 From: Yohan Boniface Date: Wed, 27 Sep 2023 11:01:50 +0200 Subject: [PATCH] Finally add Map.create_at field This field should have been added at the beginning, but this is like planting trees, isn't it ? --- umap/migrations/0014_map_created_at.py | 23 +++++++++++++++++++++++ umap/models.py | 1 + 2 files changed, 24 insertions(+) create mode 100644 umap/migrations/0014_map_created_at.py diff --git a/umap/migrations/0014_map_created_at.py b/umap/migrations/0014_map_created_at.py new file mode 100644 index 00000000..5768776c --- /dev/null +++ b/umap/migrations/0014_map_created_at.py @@ -0,0 +1,23 @@ +# Generated by Django 4.2.2 on 2023-09-27 08:50 + +from django.db import migrations, models +import django.utils.timezone + + +class Migration(migrations.Migration): + dependencies = [ + ("umap", "0013_datalayer_edit_status"), + ] + + operations = [ + migrations.AddField( + model_name="map", + name="created_at", + field=models.DateTimeField( + auto_now_add=True, default=django.utils.timezone.now + ), + preserve_default=False, + ), + # Did not find a way to provide default from a column in the field creation + migrations.RunSQL("UPDATE umap_map SET created_at=modified_at;"), + ] diff --git a/umap/models.py b/umap/models.py index 86c69518..b2d1a9a6 100644 --- a/umap/models.py +++ b/umap/models.py @@ -163,6 +163,7 @@ class Map(NamedModel): on_delete=models.SET_DEFAULT, default=get_default_licence, ) + created_at = models.DateTimeField(auto_now_add=True) modified_at = models.DateTimeField(auto_now=True) owner = models.ForeignKey( settings.AUTH_USER_MODEL,