MCPcopy
hub / github.com/PokeAPI/pokeapi / AbilityDetailSerializer

Class AbilityDetailSerializer

pokemon_v2/serializers.py:1336–1400  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

1334
1335
1336class AbilityDetailSerializer(serializers.ModelSerializer):
1337 effect_entries = AbilityEffectTextSerializer(
1338 many=True, read_only=True, source="abilityeffecttext"
1339 )
1340 flavor_text_entries = AbilityFlavorTextSerializer(
1341 many=True, read_only=True, source="abilityflavortext"
1342 )
1343 names = AbilityNameSerializer(many=True, read_only=True, source="abilityname")
1344 generation = GenerationSummarySerializer()
1345 effect_changes = AbilityChangeSerializer(
1346 many=True, read_only=True, source="abilitychange"
1347 )
1348 pokemon = serializers.SerializerMethodField("get_ability_pokemon")
1349
1350 class Meta:
1351 model = Ability
1352 fields = (
1353 "id",
1354 "name",
1355 "is_main_series",
1356 "generation",
1357 "names",
1358 "effect_entries",
1359 "effect_changes",
1360 "flavor_text_entries",
1361 "pokemon",
1362 )
1363
1364 @extend_schema_field(
1365 field={
1366 "type": "array",
1367 "items": {
1368 "type": "object",
1369 "required": ["is_hidden", "slot", "pokemon"],
1370 "properties": {
1371 "is_hidden": {"type": "boolean"},
1372 "slot": {"type": "integer", "format": "int32", "examples": [3]},
1373 "pokemon": {
1374 "type": "object",
1375 "required": ["name", "url"],
1376 "properties": {
1377 "name": {"type": "string", "examples": ["gloom"]},
1378 "url": {
1379 "type": "string",
1380 "format": "uri",
1381 "examples": ["https://pokeapi.co/api/v2/pokemon/44/"],
1382 },
1383 },
1384 },
1385 },
1386 },
1387 }
1388 )
1389 def get_ability_pokemon(self, obj):
1390 pokemon_ability_objects = PokemonAbility.objects.filter(ability=obj)
1391 data = PokemonAbilitySerializer(
1392 pokemon_ability_objects, many=True, context=self.context
1393 ).data

Callers

nothing calls this directly

Tested by

no test coverage detected