Language should be totally done.

This commit is contained in:
Zane Adickes 2015-09-11 08:15:45 -04:00
parent a0c0d62699
commit bcc7ea9df4
2 changed files with 61 additions and 31 deletions

View file

@ -9,16 +9,34 @@ PokeAPI v2 serializers
from .models import *
class LanguageListSerializer(serializers.HyperlinkedModelSerializer):
##########################
# LANGUAGE SERIALIZERS #
##########################
class LanguageNameSerializer(serializers.ModelSerializer):
local_language_url = serializers.HyperlinkedRelatedField(read_only='True', source="local_language_id", view_name='language-detail')
class Meta:
model = LanguageName
fields = ('name', 'local_language_url')
class LanguageSummarySerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Language
fields = ('name', 'url')
class LanguageSerializer(serializers.ModelSerializer):
class LanguageDetailSerializer(serializers.ModelSerializer):
names = LanguageNameSerializer(many=True, read_only=True, source='languagename_language')
class Meta:
model = Language
fields = ('name', 'official', 'iso639', 'iso3166', 'id', 'names')
#########################
# ABILITY SERIALIZERS #
@ -26,6 +44,8 @@ class LanguageSerializer(serializers.ModelSerializer):
class AbilityDescriptionSerializer(serializers.ModelSerializer):
language = LanguageSummarySerializer()
class Meta:
model = AbilityDescription
fields = ('effect', 'short_effect', 'language')
@ -34,38 +54,62 @@ class AbilityDescriptionSerializer(serializers.ModelSerializer):
class AbilityFlavorTextSerializer(serializers.ModelSerializer):
text = serializers.CharField(source="flavor_text")
language = LanguageListSerializer()
language = LanguageSummarySerializer()
class Meta:
model = AbilityFlavorText
fields = ('text', 'language', 'version_group')
fields = ('text', 'version_group', 'language')
class AbilityNameSerializer(serializers.ModelSerializer):
language = LanguageSummarySerializer()
class Meta:
model = AbilityName
fields = ('name', 'language')
class AbilityListSerializer(serializers.HyperlinkedModelSerializer):
class AbilitySummarySerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Ability
class AbilitySerializer(serializers.HyperlinkedModelSerializer):
class AbilityDetailSerializer(serializers.HyperlinkedModelSerializer):
descriptions = AbilityDescriptionSerializer(many=True, read_only=True, source="abilitydescription")
flavor_text_entries = AbilityFlavorTextSerializer(many=True, read_only=True, source="abilityflavortext")
names = AbilityNameSerializer(many=True, read_only=True, source="abilityname")
# names = serializers.SerializerMethodField('get_names_by_language')
# descriptions = serializers.SerializerMethodField('get_descriptions_by_language')
# flavor_text_entries = serializers.SerializerMethodField('get_flavor_text_by_language')
# def get_names_by_language(self, obj):
# language_filter = self.context['request'].query_params['language']
# names = AbilityName.objects.filter(ability=obj, language=9)
# serializer = AbilityNameSerializer(names, many=True, context=self.context)
# return serializer.data
# def get_flavor_text_by_language(self, obj):
# language_filter = self.context['request'].query_params['language']
# flavor_text_entries = AbilityFlavorText.objects.filter(ability=obj, language=9)
# serializer = AbilityFlavorTextSerializer(flavor_text_entries, many=True, context=self.context)
# return serializer.data
# def get_descriptions_by_language(self, obj):
# language_filter = self.context['request'].query_params['language']
# descriptions = AbilityDescription.objects.filter(ability=obj, language=9)
# serializer = AbilityDescriptionSerializer(descriptions, many=True, context=self.context)
# return serializer.data
class Meta:
model = Ability
fields = (
'id',
'name',
'is_main_series',
'is_main_series',
'generation',
'names',
'descriptions',

View file

@ -60,58 +60,44 @@ class PokeapiCommonViewset(ListOrDetailSerialRelation, NameOrIdRetrieval, viewse
##########
class AbilityResource(PokeapiCommonViewset):
"""
Views for the Ability V2 Resource
"""
queryset = Ability.objects.all()
serializer_class = AbilitySerializer
list_serializer_class = AbilityListSerializer
serializer_class = AbilityDetailSerializer
list_serializer_class = AbilitySummarySerializer
class GenerationResource(PokeapiCommonViewset):
"""
Views for the Generation V2 Resource
"""
queryset = Generation.objects.all()
serializer_class = GenerationSerializer
class LanguageResource(PokeapiCommonViewset):
"""
Views for the Generation V2 Resource
"""
queryset = Language.objects.all()
serializer_class = LanguageSerializer
serializer_class = LanguageDetailSerializer
class MoveResource(PokeapiCommonViewset):
"""
Views for the Move V2 Resource
"""
queryset = Move.objects.all()
serializer_class = MoveSerializer
class NatureResource(PokeapiCommonViewset):
"""
Views for the Nature V2 Resource
"""
queryset = Nature.objects.all()
serializer_class = NatureSerializer
class PokemonResource(PokeapiCommonViewset):
"""
Views for the Pokemon V2 Resource
"""
queryset = Pokemon.objects.all()
serializer_class = PokemonSerializer
class TypeResource(PokeapiCommonViewset):
"""
Views for the Type V2 Resource
"""
queryset = Type.objects.all()
serializer_class = TypeSerializer