diff --git a/pokemon_v2/api.py b/pokemon_v2/api.py index b2c9793e..f5a9a3a0 100644 --- a/pokemon_v2/api.py +++ b/pokemon_v2/api.py @@ -240,6 +240,13 @@ class LocationAreaResource(ListOrDetailSerialRelation, IncrementingReadOnlyModel list_serializer_class = LocationAreaSummarySerializer +class MachineResource(PokeapiCommonViewset): + + queryset = Machine.objects.all() + serializer_class = MachineDetailSerializer + list_serializer_class = MachineSummarySerializer + + class MoveResource(PokeapiCommonViewset): queryset = Move.objects.all() diff --git a/pokemon_v2/serializers.py b/pokemon_v2/serializers.py index d7c214db..6e1b6a1c 100644 --- a/pokemon_v2/serializers.py +++ b/pokemon_v2/serializers.py @@ -1354,6 +1354,7 @@ class ItemDetailSerializer(serializers.ModelSerializer): held_by_pokemon = serializers.SerializerMethodField(source='get_held_by_pokemon') baby_trigger_for = serializers.SerializerMethodField(source='get_baby_trigger_for') sprites = serializers.SerializerMethodField('get_item_sprites') + machines = serializers.SerializerMethodField('get_item_machines') class Meta: model = Item @@ -1371,9 +1372,31 @@ class ItemDetailSerializer(serializers.ModelSerializer): 'names', 'held_by_pokemon', 'sprites', - 'baby_trigger_for' + 'baby_trigger_for', + 'machines', ) + def get_item_machines(self, obj): + + machine_objects = Machine.objects.filter(item=obj) + + machines = [] + + for machine_object in machine_objects: + + machine_data = MachineSummarySerializer( + machine_object, context=self.context).data + + version_group_data = VersionGroupSummarySerializer( + machine_object.version_group, context=self.context).data + + machines.append({ + 'machine': machine_data, + 'version_group': version_group_data + }) + + return machines + def get_item_sprites(self, obj): sprites_object = ItemSprites.objects.get(item_id=obj) @@ -1743,7 +1766,7 @@ class TypeDetailSerializer(serializers.ModelSerializer): class MachineDetailSerializer(serializers.ModelSerializer): item = ItemSummarySerializer() - version_group = VersionSummarySerializer() + version_group = VersionGroupSummarySerializer() move = MoveSummarySerializer() class Meta: @@ -2006,6 +2029,7 @@ class MoveDetailSerializer(serializers.ModelSerializer): super_contest_effect = SuperContestEffectSummarySerializer() past_values = MoveChangeSerializer(many=True, read_only=True, source="movechange") effect_changes = serializers.SerializerMethodField('get_effect_change_text') + machines = serializers.SerializerMethodField('get_move_machines') class Meta: model = Move @@ -2030,9 +2054,30 @@ class MoveDetailSerializer(serializers.ModelSerializer): 'stat_changes', 'super_contest_effect', 'target', - 'type' + 'type', + 'machines', ) + def get_move_machines(self, obj): + + machine_objects = Machine.objects.filter(move=obj) + + machines = [] + + for machine_object in machine_objects: + machine_data = MachineSummarySerializer( + machine_object, context=self.context).data + + version_group_data = VersionGroupSummarySerializer( + machine_object.version_group, context=self.context).data + + machines.append({ + 'machine': machine_data, + 'version_group': version_group_data + }) + + return machines + def get_combos(self, obj): normal_before_objects = ContestCombo.objects.filter(first_move=obj) diff --git a/pokemon_v2/urls.py b/pokemon_v2/urls.py index 066378dc..d3ce585f 100644 --- a/pokemon_v2/urls.py +++ b/pokemon_v2/urls.py @@ -38,6 +38,7 @@ router.register(r"item-pocket", ItemPocketResource) router.register(r"language", LanguageResource) router.register(r"location", LocationResource) router.register(r"location-area", LocationAreaResource) +router.register(r"machine", MachineResource) router.register(r"move", MoveResource) router.register(r"move-ailment", MoveMetaAilmentResource) router.register(r"move-battle-style", MoveBattleStyleResource) diff --git a/templates/pages/docsv2.html b/templates/pages/docsv2.html index 36ea9a40..9f591791 100644 --- a/templates/pages/docsv2.html +++ b/templates/pages/docsv2.html @@ -77,6 +77,12 @@ +
  • Machines + +
  • +
  • Moves @@ -37,6 +37,7 @@
  • Languages
  • Locations
  • Location Areas
  • +
  • Machines
  • Moves
  • Move Ailments
  • Move Battle Styles
  • @@ -44,11 +45,11 @@
  • Move Damage Classes
  • Move Learn Methods
  • Move Targets
  • -
  • Natures