From 02c2c43e1f947b3f28482ef9d99355b4e9ca8f93 Mon Sep 17 00:00:00 2001 From: August Johnson Date: Wed, 9 Oct 2024 11:45:34 -0500 Subject: [PATCH] Distance on size now. --- api_v2/migrations/0005_size_distance_unit.py | 18 ++++++++++++++++++ api_v2/models/size.py | 12 +++++++++--- api_v2/serializers/size.py | 4 ++++ data/v2/en-publishing/mmenag/Size.json | 3 ++- data/v2/wizards-of-the-coast/srd/Size.json | 18 ++++++++++++------ 5 files changed, 45 insertions(+), 10 deletions(-) create mode 100644 api_v2/migrations/0005_size_distance_unit.py diff --git a/api_v2/migrations/0005_size_distance_unit.py b/api_v2/migrations/0005_size_distance_unit.py new file mode 100644 index 00000000..26f81efd --- /dev/null +++ b/api_v2/migrations/0005_size_distance_unit.py @@ -0,0 +1,18 @@ +# Generated by Django 5.1.1 on 2024-10-09 16:44 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('api_v2', '0004_alter_size_space_diameter'), + ] + + operations = [ + migrations.AddField( + model_name='size', + name='distance_unit', + field=models.CharField(blank=True, choices=[('feet', 'feet'), ('miles', 'miles')], help_text='What distance unit the relevant field uses.', max_length=20, null=True), + ), + ] diff --git a/api_v2/models/size.py b/api_v2/models/size.py index 1ec59d81..a3bcfa68 100644 --- a/api_v2/models/size.py +++ b/api_v2/models/size.py @@ -1,8 +1,7 @@ from django.db import models -from django.core.validators import MinValueValidator from .abstracts import HasName -from .abstracts import distance_field +from .abstracts import distance_field, distance_unit_field from .document import FromDocument class Size(HasName, FromDocument): @@ -17,4 +16,11 @@ class Size(HasName, FromDocument): unique=True, help_text='Ranking of the size, smallest has the lowest values.') - space_diameter = distance_field() \ No newline at end of file + space_diameter = distance_field() + distance_unit = distance_unit_field() + + @property + def get_distance_unit(self): + if self.distance_unit is None: + return self.document.distance_unit + return self.distance_unit diff --git a/api_v2/serializers/size.py b/api_v2/serializers/size.py index 6d57ee05..39bc2814 100644 --- a/api_v2/serializers/size.py +++ b/api_v2/serializers/size.py @@ -9,7 +9,11 @@ class SizeSerializer(GameContentSerializer): """Serializer for the Size type""" key = serializers.ReadOnlyField() + distance_unit = serializers.SerializerMethodField() class Meta: model = models.Size fields = '__all__' + + def get_distance_unit(self, Size): + return Size.get_distance_unit diff --git a/data/v2/en-publishing/mmenag/Size.json b/data/v2/en-publishing/mmenag/Size.json index d4ab8328..10337c72 100644 --- a/data/v2/en-publishing/mmenag/Size.json +++ b/data/v2/en-publishing/mmenag/Size.json @@ -6,7 +6,8 @@ "name": "Titanic", "document": "mmenag", "rank": 7, - "space_diameter": 25.0 + "space_diameter": 25.0, + "distance_unit": null } } ] diff --git a/data/v2/wizards-of-the-coast/srd/Size.json b/data/v2/wizards-of-the-coast/srd/Size.json index 590b9344..07ef0461 100644 --- a/data/v2/wizards-of-the-coast/srd/Size.json +++ b/data/v2/wizards-of-the-coast/srd/Size.json @@ -6,7 +6,8 @@ "name": "Gargantuan", "document": "srd", "rank": 6, - "space_diameter": 20.0 + "space_diameter": 20.0, + "distance_unit": null } }, { @@ -16,7 +17,8 @@ "name": "Huge", "document": "srd", "rank": 5, - "space_diameter": 15.0 + "space_diameter": 15.0, + "distance_unit": null } }, { @@ -26,7 +28,8 @@ "name": "Large", "document": "srd", "rank": 4, - "space_diameter": 10.0 + "space_diameter": 10.0, + "distance_unit": null } }, { @@ -36,7 +39,8 @@ "name": "Medium", "document": "srd", "rank": 3, - "space_diameter": 5.0 + "space_diameter": 5.0, + "distance_unit": null } }, { @@ -46,7 +50,8 @@ "name": "Small", "document": "srd", "rank": 2, - "space_diameter": 5.0 + "space_diameter": 5.0, + "distance_unit": null } }, { @@ -56,7 +61,8 @@ "name": "Tiny", "document": "srd", "rank": 1, - "space_diameter": 2.5 + "space_diameter": 2.5, + "distance_unit": null } } ]