Add data updated date to unsplash model

Used later on for an update script
This commit is contained in:
Jake Howard 2022-07-12 22:53:50 +01:00
parent b155ec2e9b
commit 70b08137bc
Signed by: jake
GPG key ID: 57AFB45680EDD477
3 changed files with 31 additions and 1 deletions

View file

@ -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),
),
]

View file

@ -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"]

View file

@ -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