Pokemon form names (#213)

* added names and form names to the pokemon-form resource

* document pokemon form names

* close #185
This commit is contained in:
Sargun Vohra 2016-06-25 12:56:24 -04:00 committed by GitHub
parent f8c641716e
commit cf19dcca29
2 changed files with 40 additions and 1 deletions

View file

@ -2233,19 +2233,56 @@ class PokemonFormSpritesSerializer(serializers.ModelSerializer):
fields = ('sprites',)
class PokemonFormNameSerializer(serializers.ModelSerializer):
language = LanguageSummarySerializer()
class Meta:
model = PokemonFormName
fields = ('name', 'pokemon_name', 'language')
class PokemonFormDetailSerializer(serializers.ModelSerializer):
pokemon = PokemonSummarySerializer()
version_group = VersionGroupSummarySerializer()
sprites = serializers.SerializerMethodField('get_pokemon_form_sprites')
form_names = serializers.SerializerMethodField('get_pokemon_form_names')
names = serializers.SerializerMethodField('get_pokemon_form_pokemon_names')
class Meta:
model = PokemonForm
fields = (
'id', 'name', 'order', 'form_order', 'is_default', 'is_battle_only',
'is_mega', 'form_name', 'pokemon', 'sprites', 'version_group'
'is_mega', 'form_name', 'pokemon', 'sprites', 'version_group',
'form_names', 'names'
)
def get_pokemon_form_names(self, obj):
form_results = PokemonFormName.objects.filter(pokemon_form=obj, name__regex=".+")
form_serializer = PokemonFormNameSerializer(form_results, many=True, context=self.context)
data = form_serializer.data
for name in data:
del name['pokemon_name']
return data
def get_pokemon_form_pokemon_names(self, obj):
form_results = PokemonFormName.objects.filter(pokemon_form=obj, pokemon_name__regex=".+")
form_serializer = PokemonFormNameSerializer(form_results, many=True, context=self.context)
data = form_serializer.data
for name in data:
name['name'] = name['pokemon_name']
del name['pokemon_name']
return data
def get_pokemon_form_sprites(self, obj):
sprites_object = PokemonFormSprites.objects.get(pokemon_form_id=obj)

View file

@ -2567,6 +2567,8 @@ Some Pokémon have the ability to take on different forms. At times, these diffe
| pokemon | The Pokémon that can take on this form | [NamedAPIResource](#namedapiresource) ([Pokemon](#pokemon)) |
| sprites | A set of sprites used to depict this Pokémon form in the game | [PokemonFormSprites](#pokemonformsprites) |
| version_group | The version group this Pokémon form was introduced in | [NamedAPIResource](#namedapiresource) ([VersionGroup](#version-groups)) |
| names | The form specific full name of this Pokémon form, or empty if the form does not have a specific name | list [Name](#name) |
| form_names | The form specific form name of this Pokémon form, or empty if the form does not have a specific name | list [Name](#name) |
#### PokemonFormSprites