From 70b08137bc88890f145d16324b8d3fe3c0526029 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Tue, 12 Jul 2022 22:53:50 +0100 Subject: [PATCH] Add data updated date to unsplash model Used later on for an update script --- .../0002_unsplashphoto_created_and_more.py | 27 +++++++++++++++++++ website/contrib/unsplash/models.py | 3 +++ website/contrib/unsplash/wagtail_hooks.py | 2 +- 3 files changed, 31 insertions(+), 1 deletion(-) create mode 100644 website/contrib/unsplash/migrations/0002_unsplashphoto_created_and_more.py diff --git a/website/contrib/unsplash/migrations/0002_unsplashphoto_created_and_more.py b/website/contrib/unsplash/migrations/0002_unsplashphoto_created_and_more.py new file mode 100644 index 0000000..d130b81 --- /dev/null +++ b/website/contrib/unsplash/migrations/0002_unsplashphoto_created_and_more.py @@ -0,0 +1,27 @@ +# Generated by Django 4.0.5 on 2022-07-12 21:51 + +import django.utils.timezone +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("unsplash", "0001_initial"), + ] + + operations = [ + migrations.AddField( + model_name="unsplashphoto", + name="created", + field=models.DateTimeField( + auto_now_add=True, default=django.utils.timezone.now + ), + preserve_default=False, + ), + migrations.AddField( + model_name="unsplashphoto", + name="data_last_updated", + field=models.DateTimeField(default=django.utils.timezone.now), + ), + ] diff --git a/website/contrib/unsplash/models.py b/website/contrib/unsplash/models.py index c7f5ab9..e2927c4 100644 --- a/website/contrib/unsplash/models.py +++ b/website/contrib/unsplash/models.py @@ -1,9 +1,12 @@ from django.db import models +from django.utils import timezone class UnsplashPhoto(models.Model): unsplash_id = models.CharField(unique=True, max_length=11, db_index=True) data = models.JSONField() + created = models.DateTimeField(auto_now_add=True) + data_last_updated = models.DateTimeField(default=timezone.now) def get_description(self) -> str: return self.data["description"] diff --git a/website/contrib/unsplash/wagtail_hooks.py b/website/contrib/unsplash/wagtail_hooks.py index 9a7111d..ab49024 100644 --- a/website/contrib/unsplash/wagtail_hooks.py +++ b/website/contrib/unsplash/wagtail_hooks.py @@ -59,7 +59,7 @@ class UnsplashPhotoEditView(EditView): @modeladmin_register class UnsplashPhotoAdmin(ModelAdmin): model = UnsplashPhoto - list_display = ["unsplash_id", "thumbnail", "description"] + list_display = ["unsplash_id", "thumbnail", "description", "data_last_updated"] form_fields_exclude = ["data"] search_fields = ["unsplash_id", "data__description"] create_view_class = UnsplashPhotoCreateView