MCPcopy Index your code
hub / github.com/PokeAPI/pokeapi / PokedexDetailSerializer

Class PokedexDetailSerializer

pokemon_v2/serializers.py:5969–6062  ·  view source on GitHub ↗

Source from the content-addressed store, hash-verified

5967
5968
5969class PokedexDetailSerializer(serializers.ModelSerializer):
5970 region = RegionSummarySerializer()
5971 names = PokedexNameSerializer(many=True, read_only=True, source="pokedexname")
5972 descriptions = PokedexDescriptionSerializer(
5973 many=True, read_only=True, source="pokedexdescription"
5974 )
5975 pokemon_entries = serializers.SerializerMethodField("get_pokedex_entries")
5976 version_groups = serializers.SerializerMethodField("get_pokedex_version_groups")
5977
5978 class Meta:
5979 model = Pokedex
5980 fields = (
5981 "id",
5982 "name",
5983 "is_main_series",
5984 "descriptions",
5985 "names",
5986 "pokemon_entries",
5987 "region",
5988 "version_groups",
5989 )
5990
5991 @extend_schema_field(
5992 field={
5993 "type": "array",
5994 "items": {
5995 "type": "object",
5996 "required": ["entry_number", "pokemon_species"],
5997 "properties": {
5998 "entry_number": {
5999 "type": "integer",
6000 "format": "int32",
6001 "examples": [1],
6002 },
6003 "pokemon_species": {
6004 "type": "object",
6005 "required": ["name", "url"],
6006 "properties": {
6007 "name": {"type": "string", "examples": ["bulbasaur"]},
6008 "url": {
6009 "type": "string",
6010 "format": "uri",
6011 "examples": [
6012 "https://pokeapi.co/api/v2/pokemon-species/1/"
6013 ],
6014 },
6015 },
6016 },
6017 },
6018 },
6019 }
6020 )
6021 def get_pokedex_entries(self, obj):
6022 results = PokemonDexNumber.objects.filter(pokedex=obj).order_by(
6023 "pokedex_number"
6024 )
6025 serializer = PokemonDexNumberSerializer(
6026 results, many=True, context=self.context

Callers

nothing calls this directly

Tested by

no test coverage detected