Skip to content

Commit

Permalink
Distance on size now.
Browse files Browse the repository at this point in the history
  • Loading branch information
augustjohnson committed Oct 9, 2024
1 parent 7b87df2 commit 02c2c43
Showing 5 changed files with 45 additions and 10 deletions.
18 changes: 18 additions & 0 deletions api_v2/migrations/0005_size_distance_unit.py
Original file line number Diff line number Diff line change
@@ -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),
),
]
12 changes: 9 additions & 3 deletions api_v2/models/size.py
Original file line number Diff line number Diff line change
@@ -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()
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
4 changes: 4 additions & 0 deletions api_v2/serializers/size.py
Original file line number Diff line number Diff line change
@@ -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
3 changes: 2 additions & 1 deletion data/v2/en-publishing/mmenag/Size.json
Original file line number Diff line number Diff line change
@@ -6,7 +6,8 @@
"name": "Titanic",
"document": "mmenag",
"rank": 7,
"space_diameter": 25.0
"space_diameter": 25.0,
"distance_unit": null
}
}
]
18 changes: 12 additions & 6 deletions data/v2/wizards-of-the-coast/srd/Size.json
Original file line number Diff line number Diff line change
@@ -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
}
}
]

0 comments on commit 02c2c43

Please sign in to comment.