diff --git a/api_v2/models/characterclass.py b/api_v2/models/characterclass.py index 03919bfa..4764229e 100644 --- a/api_v2/models/characterclass.py +++ b/api_v2/models/characterclass.py @@ -113,4 +113,12 @@ def as_text(self): return text + def search_result_extra_fields(self): + return { + "subclass_of": { + "name": self.subclass_of.name, + "key": self.subclass_of.key + } if self.subclass_of else None + } + #TODO add verbose name plural \ No newline at end of file diff --git a/api_v2/models/creature.py b/api_v2/models/creature.py index cfcd2c84..a11aeab8 100644 --- a/api_v2/models/creature.py +++ b/api_v2/models/creature.py @@ -82,10 +82,10 @@ def as_text(self): def search_result_extra_fields(self): return { - "armor_class":self.armor_class, - "hit_points":self.hit_points, - "ability_scores":self.get_ability_scores(), - } + "cr": self.challenge_rating_text, + "type": self.type.name, + "size": self.size.name, + } @property def creatureset(self): diff --git a/api_v2/models/item.py b/api_v2/models/item.py index e3d19dc1..13cb4eda 100644 --- a/api_v2/models/item.py +++ b/api_v2/models/item.py @@ -81,11 +81,11 @@ def is_magic_item(self): return self.rarity is not None def search_result_extra_fields(self): - fields = {"type":self.category.key} - if self.is_magic_item: - fields["rarity"]=self.rarity.key - return fields - + return { + "is_magic_item": self.is_magic_item, + "type": self.category.name if self.is_magic_item else None, + "rarity": self.rarity.name if self.is_magic_item else None, + } class ItemSet(HasName, HasDescription, FromDocument): diff --git a/api_v2/models/race.py b/api_v2/models/race.py index 94f19136..f926a20b 100644 --- a/api_v2/models/race.py +++ b/api_v2/models/race.py @@ -39,6 +39,13 @@ def traits(self): """Returns the set of traits that are related to this race.""" return self.racetrait_set + def search_result_extra_fields(self): + return { + "subrace_of": { + "name": self.subrace_of.name, + "key": self.subrace_of.key + } if self.subrace_of else None + } class Meta: """To assist with the UI layer.""" diff --git a/api_v2/models/spell.py b/api_v2/models/spell.py index 63d31acc..205d0162 100644 --- a/api_v2/models/spell.py +++ b/api_v2/models/spell.py @@ -142,7 +142,12 @@ def get_range_unit(self): return self.document.distance_unit return self.range_unit - + def search_result_extra_fields(self): + return { + "school": self.school.name, + "level": self.level, + } + class SpellCastingOption(models.Model): """An object representing an alternative way to cast a spell.""" diff --git a/api_v2/serializers/search.py b/api_v2/serializers/search.py index 70486f3f..8b01c99c 100644 --- a/api_v2/serializers/search.py +++ b/api_v2/serializers/search.py @@ -39,7 +39,7 @@ def get_object(self, obj): result_detail = v1.Spell.objects.get(slug=obj.object_pk) if obj.object_model == 'Section': result_detail = v1.Section.objects.get(slug=obj.object_pk) - + if obj.schema_version == 'v2': if obj.object_model == 'Item': result_detail = models.Item.objects.get(pk=obj.object_pk) @@ -47,6 +47,10 @@ def get_object(self, obj): result_detail = models.Creature.objects.get(pk=obj.object_pk) if obj.object_model == 'Spell': result_detail = models.Spell.objects.get(pk=obj.object_pk) + if obj.object_model == 'CharacterClass': + result_detail = models.CharacterClass.objects.get(pk=obj.object_pk) + if obj.object_model == 'Race': + result_detail = models.Race.objects.get(pk=obj.object_pk) if result_detail is not None: return result_detail.search_result_extra_fields()