From 079ca51a53fd7ffde1d7ce639bcf197da790518a Mon Sep 17 00:00:00 2001 From: BuildTools Date: Sat, 28 Oct 2023 08:16:47 -0500 Subject: [PATCH] I believe it's ready for data entry now. --- .../migrations/0011_alter_creatureset_type.py | 18 +++++++++++++++ .../migrations/0012_alter_creatureset_type.py | 18 +++++++++++++++ api_v2/models/creature.py | 3 ++- api_v2/serializers.py | 22 +++++++++++-------- 4 files changed, 51 insertions(+), 10 deletions(-) create mode 100644 api_v2/migrations/0011_alter_creatureset_type.py create mode 100644 api_v2/migrations/0012_alter_creatureset_type.py diff --git a/api_v2/migrations/0011_alter_creatureset_type.py b/api_v2/migrations/0011_alter_creatureset_type.py new file mode 100644 index 00000000..1821b3ad --- /dev/null +++ b/api_v2/migrations/0011_alter_creatureset_type.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.20 on 2023-10-28 12:48 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('api_v2', '0010_creatureset'), + ] + + operations = [ + migrations.AlterField( + model_name='creatureset', + name='type', + field=models.TextField(choices=[('MONSTER_TYPE', 'Monster Type'), ('TAG', 'Tag')]), + ), + ] diff --git a/api_v2/migrations/0012_alter_creatureset_type.py b/api_v2/migrations/0012_alter_creatureset_type.py new file mode 100644 index 00000000..6c801cd2 --- /dev/null +++ b/api_v2/migrations/0012_alter_creatureset_type.py @@ -0,0 +1,18 @@ +# Generated by Django 3.2.20 on 2023-10-28 13:16 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('api_v2', '0011_alter_creatureset_type'), + ] + + operations = [ + migrations.AlterField( + model_name='creatureset', + name='type', + field=models.TextField(choices=[('TYPE', 'Type'), ('TAG', 'Tag')]), + ), + ] diff --git a/api_v2/models/creature.py b/api_v2/models/creature.py index 0f6a392f..dd19f4ff 100644 --- a/api_v2/models/creature.py +++ b/api_v2/models/creature.py @@ -198,7 +198,8 @@ class CreatureAttack(HasName, FromDocument): class CreatureSet(HasName, HasDescription, FromDocument): """A set of Creatures to be referenced.""" - CREATURE_SET_TYPE_CHOICES = [('MONSTER_TYPE', "Monster Type")] + CREATURE_SET_TYPE_CHOICES = [('TYPE', "Type"), + ('TAG', "Tag")] type = models.TextField(choices=CREATURE_SET_TYPE_CHOICES) diff --git a/api_v2/serializers.py b/api_v2/serializers.py index f33832b6..e3a854dc 100644 --- a/api_v2/serializers.py +++ b/api_v2/serializers.py @@ -238,6 +238,15 @@ def make_action_obj(action): return obj + +class CreatureSetSerializer(serializers.ModelSerializer): + key = serializers.ReadOnlyField() + + class Meta: + model = models.CreatureSet + fields = '__all__' + + class CreatureSerializer(GameContentSerializer): key = serializers.ReadOnlyField() @@ -248,6 +257,7 @@ class CreatureSerializer(GameContentSerializer): skill_bonuses = serializers.SerializerMethodField() all_skill_bonuses = serializers.SerializerMethodField() actions = serializers.SerializerMethodField() + creaturesets = serializers.SerializerMethodField() class Meta: model = models.Creature @@ -257,9 +267,8 @@ class Meta: 'key', 'name', 'category', - 'size', - 'type', 'creaturesets', + 'size', 'subtype', 'alignment', 'weight', @@ -368,10 +377,5 @@ def get_actions(self, creature): result.append(action_obj) return result - -class CreatureSetSerializer(GameContentSerializer): - key = serializers.ReadOnlyField() - - class Meta: - model = models.CreatureSet - fields = '__all__' + def get_creaturesets(self, creature): + return creature.creaturesets.all().values("key","type")