From c74fdafaf98eb712d9127e9e01bded6031016814 Mon Sep 17 00:00:00 2001 From: Gilles <43683714+corp-0@users.noreply.github.com> Date: Sat, 11 Nov 2023 19:57:38 -0300 Subject: [PATCH] feat: added last_updated field for conflict conciliation --- src/persistence/api/serializers.py | 4 ++-- .../migrations/0002_character_last_updated.py | 18 ++++++++++++++++++ src/persistence/models.py | 5 +++++ 3 files changed, 25 insertions(+), 2 deletions(-) create mode 100644 src/persistence/migrations/0002_character_last_updated.py diff --git a/src/persistence/api/serializers.py b/src/persistence/api/serializers.py index 33cade3..ff98635 100644 --- a/src/persistence/api/serializers.py +++ b/src/persistence/api/serializers.py @@ -19,7 +19,7 @@ class Meta: "data", ) - read_only_fields = ("id",) + read_only_fields = ("id", "last_updated") class UpdateCharacterSerializer(serializers.ModelSerializer): @@ -33,7 +33,7 @@ class Meta: "data", ) - read_only_fields = ("id", "account") + read_only_fields = ("id", "account", "last_updated") class OtherSerializer(serializers.ModelSerializer): diff --git a/src/persistence/migrations/0002_character_last_updated.py b/src/persistence/migrations/0002_character_last_updated.py new file mode 100644 index 0000000..6b47916 --- /dev/null +++ b/src/persistence/migrations/0002_character_last_updated.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.22 on 2023-11-11 22:53 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('persistence', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='character', + name='last_updated', + field=models.DateTimeField(auto_now=True, help_text='When was this character last updated? Useful for conciliation with the local cache of a character.'), + ), + ] diff --git a/src/persistence/models.py b/src/persistence/models.py index a3554c1..46d2052 100644 --- a/src/persistence/models.py +++ b/src/persistence/models.py @@ -26,6 +26,11 @@ class Character(models.Model): ) """The character data.""" + last_updated = models.DateTimeField( + auto_now=True, + help_text="When was this character last updated? Useful for conciliation with the local cache of a character.", + ) + def __str__(self): return f"{self.account.unique_identifier}'s character"