mirror of
https://github.com/PokeAPI/pokeapi
synced 2024-11-22 11:23:13 +00:00
little more work on pokemon evolution chains
This commit is contained in:
parent
163e29c527
commit
6d7fd53ece
9 changed files with 568 additions and 107 deletions
|
@ -42,9 +42,9 @@ MEDIA_ROOT = PROJECT_ROOT.child('media')
|
||||||
|
|
||||||
MEDIA_URL = '/media/'
|
MEDIA_URL = '/media/'
|
||||||
|
|
||||||
STATIC_ROOT = PROJECT_ROOT.child('static')
|
STATIC_ROOT = PROJECT_ROOT.child('assets')
|
||||||
|
|
||||||
STATIC_URL = '/static/'
|
STATIC_URL = '/assets/'
|
||||||
|
|
||||||
ALLOWED_HOSTS = ['localhost']
|
ALLOWED_HOSTS = ['localhost']
|
||||||
|
|
||||||
|
|
|
@ -48,8 +48,15 @@ from pokemon_v2.views import *
|
||||||
router = routers.DefaultRouter()
|
router = routers.DefaultRouter()
|
||||||
|
|
||||||
router.register(r"ability", AbilityResource)
|
router.register(r"ability", AbilityResource)
|
||||||
|
router.register(r"berry", BerryResource)
|
||||||
|
router.register(r"egg-group", EggGroupResource)
|
||||||
router.register(r"generation", GenerationResource)
|
router.register(r"generation", GenerationResource)
|
||||||
router.register(r"growth-rate", GrowthRateResource)
|
router.register(r"growth-rate", GrowthRateResource)
|
||||||
|
router.register(r"item", ItemResource)
|
||||||
|
router.register(r"item-category", ItemCategoryResource)
|
||||||
|
router.register(r"item-attribute", ItemFlagResource)
|
||||||
|
router.register(r"item-fling-effect", ItemFlingEffectResource)
|
||||||
|
router.register(r"item-pocket", ItemPocketResource)
|
||||||
router.register(r"language", LanguageResource)
|
router.register(r"language", LanguageResource)
|
||||||
router.register(r"move", MoveResource)
|
router.register(r"move", MoveResource)
|
||||||
router.register(r"move-ailment", MoveMetaAilmentResource)
|
router.register(r"move-ailment", MoveMetaAilmentResource)
|
||||||
|
@ -60,7 +67,9 @@ router.register(r"move-target", MoveTargetResource)
|
||||||
router.register(r"nature", NatureResource)
|
router.register(r"nature", NatureResource)
|
||||||
router.register(r"pokedex", PokedexResource)
|
router.register(r"pokedex", PokedexResource)
|
||||||
router.register(r"pokemon", PokemonResource)
|
router.register(r"pokemon", PokemonResource)
|
||||||
|
router.register(r"pokemon-habitat", PokemonHabitatResource)
|
||||||
router.register(r"pokemon-shape", PokemonShapeResource)
|
router.register(r"pokemon-shape", PokemonShapeResource)
|
||||||
|
router.register(r"pokemon-species", PokemonSpeciesResource)
|
||||||
router.register(r"pokemon-color", PokemonColorResource)
|
router.register(r"pokemon-color", PokemonColorResource)
|
||||||
router.register(r"region", RegionResource)
|
router.register(r"region", RegionResource)
|
||||||
router.register(r"stat", StatResource)
|
router.register(r"stat", StatResource)
|
||||||
|
|
|
@ -497,7 +497,8 @@ for index, info in enumerate(data):
|
||||||
if index > 0:
|
if index > 0:
|
||||||
|
|
||||||
model = ItemFlingEffect (
|
model = ItemFlingEffect (
|
||||||
id = int(info[0])
|
id = int(info[0]),
|
||||||
|
name = info[1]
|
||||||
)
|
)
|
||||||
model.save()
|
model.save()
|
||||||
|
|
||||||
|
|
|
@ -1,8 +1,8 @@
|
||||||
id
|
id,identifier
|
||||||
1
|
1,badly-poison
|
||||||
2
|
2,burn
|
||||||
3
|
3,berry-effect
|
||||||
4
|
4,herb-effect
|
||||||
5
|
5,paralyze
|
||||||
6
|
6,poison
|
||||||
7
|
7,flinch
|
||||||
|
|
|
20
pokemon_v2/migrations/0002_itemflingeffect_name.py
Normal file
20
pokemon_v2/migrations/0002_itemflingeffect_name.py
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import models, migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('pokemon_v2', '0001_squashed_0013_auto_20150926_0913'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AddField(
|
||||||
|
model_name='itemflingeffect',
|
||||||
|
name='name',
|
||||||
|
field=models.CharField(default='name', max_length=100),
|
||||||
|
preserve_default=False,
|
||||||
|
),
|
||||||
|
]
|
20
pokemon_v2/migrations/0003_auto_20150928_1710.py
Normal file
20
pokemon_v2/migrations/0003_auto_20150928_1710.py
Normal file
|
@ -0,0 +1,20 @@
|
||||||
|
# -*- coding: utf-8 -*-
|
||||||
|
from __future__ import unicode_literals
|
||||||
|
|
||||||
|
from django.db import models, migrations
|
||||||
|
|
||||||
|
|
||||||
|
class Migration(migrations.Migration):
|
||||||
|
|
||||||
|
dependencies = [
|
||||||
|
('pokemon_v2', '0002_itemflingeffect_name'),
|
||||||
|
]
|
||||||
|
|
||||||
|
operations = [
|
||||||
|
migrations.AlterField(
|
||||||
|
model_name='pokemonhabitatname',
|
||||||
|
name='pokemon_habitat',
|
||||||
|
field=models.ForeignKey(related_name='pokemonhabitatname', blank=True, to='pokemon_v2.PokemonHabitat', null=True),
|
||||||
|
preserve_default=True,
|
||||||
|
),
|
||||||
|
]
|
|
@ -584,7 +584,7 @@ class ItemCategoryName(IsName, HasItemCategory):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
class ItemFlingEffect(models.Model):
|
class ItemFlingEffect(HasName):
|
||||||
pass
|
pass
|
||||||
|
|
||||||
|
|
||||||
|
@ -1287,7 +1287,7 @@ class PokemonHabitat(HasName):
|
||||||
|
|
||||||
class PokemonHabitatName(IsName):
|
class PokemonHabitatName(IsName):
|
||||||
|
|
||||||
pokemon_habitat = models.ForeignKey(PokemonHabitat, blank=True, null=True)
|
pokemon_habitat = models.ForeignKey(PokemonHabitat, blank=True, null=True, related_name="%(class)s")
|
||||||
|
|
||||||
|
|
||||||
class PokemonItem(HasPokemon, HasVersion, HasItem):
|
class PokemonItem(HasPokemon, HasVersion, HasItem):
|
||||||
|
|
|
@ -9,7 +9,6 @@ PokeAPI v2 serializers in order of dependency
|
||||||
|
|
||||||
from .models import *
|
from .models import *
|
||||||
|
|
||||||
|
|
||||||
##########################
|
##########################
|
||||||
# LANGUAGE SERIALIZERS #
|
# LANGUAGE SERIALIZERS #
|
||||||
##########################
|
##########################
|
||||||
|
@ -98,9 +97,16 @@ class GenerationDetailSerializer(serializers.ModelSerializer):
|
||||||
fields = ('id', 'name', 'region', 'names')
|
fields = ('id', 'name', 'region', 'names')
|
||||||
|
|
||||||
|
|
||||||
############################
|
#############################
|
||||||
# GENERATION SERIALIZERS #
|
# GROWTH RATE SERIALIZERS #
|
||||||
############################
|
#############################
|
||||||
|
|
||||||
|
class ExperienceSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = Experience
|
||||||
|
fields = ('level', 'experience')
|
||||||
|
|
||||||
|
|
||||||
class GrowthRateDescriptionSerializer(serializers.ModelSerializer):
|
class GrowthRateDescriptionSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
|
@ -121,10 +127,11 @@ class GrowthRateSummarySerializer(serializers.HyperlinkedModelSerializer):
|
||||||
class GrowthRateDetailSerializer(serializers.ModelSerializer):
|
class GrowthRateDetailSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
descriptions = GrowthRateDescriptionSerializer(many=True, read_only=True, source="growthratedescription")
|
descriptions = GrowthRateDescriptionSerializer(many=True, read_only=True, source="growthratedescription")
|
||||||
|
levels = ExperienceSerializer(many=True, read_only=True, source="experience")
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = GrowthRate
|
model = GrowthRate
|
||||||
fields = ('id', 'name', 'formula', 'descriptions')
|
fields = ('id', 'name', 'formula', 'descriptions', 'levels')
|
||||||
|
|
||||||
|
|
||||||
#########################
|
#########################
|
||||||
|
@ -258,6 +265,301 @@ class StatDetailSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#############################
|
||||||
|
# ITEM POCKET SERIALIZERS #
|
||||||
|
#############################
|
||||||
|
|
||||||
|
class ItemPocketNameSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
|
language = LanguageSummarySerializer()
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = ItemName
|
||||||
|
fields = ('name', 'language')
|
||||||
|
|
||||||
|
class ItemPocketSummarySerializer(serializers.HyperlinkedModelSerializer):
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = ItemPocket
|
||||||
|
fields = ('name', 'url')
|
||||||
|
|
||||||
|
|
||||||
|
class ItemPocketDetailSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
|
names = ItemPocketNameSerializer(many=True, read_only=True, source="itempocketname")
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = ItemPocket
|
||||||
|
fields = ('id', 'name', 'names')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
###############################
|
||||||
|
# ITEM CATEGORY SERIALIZERS #
|
||||||
|
###############################
|
||||||
|
|
||||||
|
class ItemCategoryNameSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
|
language = LanguageSummarySerializer()
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = ItemName
|
||||||
|
fields = ('name', 'language')
|
||||||
|
|
||||||
|
|
||||||
|
class ItemCategorySummarySerializer(serializers.HyperlinkedModelSerializer):
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = ItemCategory
|
||||||
|
fields = ('name', 'url')
|
||||||
|
|
||||||
|
|
||||||
|
class ItemCategoryDetailSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
|
names = ItemCategoryNameSerializer(many=True, read_only=True, source="itemcategoryname")
|
||||||
|
pocket = ItemPocketSummarySerializer(source="item_pocket")
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = ItemCategory
|
||||||
|
fields = ('id', 'name', 'pocket', 'names')
|
||||||
|
|
||||||
|
|
||||||
|
###########################
|
||||||
|
# ITEM FLAG SERIALIZERS #
|
||||||
|
###########################
|
||||||
|
|
||||||
|
# Calling these Attributes instead of Flags cause I think that just makes more sense
|
||||||
|
# Probably should change the names of the models as well. Work To Do.
|
||||||
|
|
||||||
|
class ItemFlagDescriptionSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
|
language = LanguageSummarySerializer()
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = ItemFlagDescription
|
||||||
|
fields = ('name', 'description', 'language')
|
||||||
|
|
||||||
|
|
||||||
|
class ItemFlagSummarySerializer(serializers.HyperlinkedModelSerializer):
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = ItemFlag
|
||||||
|
fields = ('name', 'url')
|
||||||
|
|
||||||
|
|
||||||
|
class ItemFlagDetailSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
|
names = serializers.SerializerMethodField('get_flag_names')
|
||||||
|
descriptions = serializers.SerializerMethodField('get_flag_descriptions')
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = ItemFlag
|
||||||
|
fields = ('id', 'name', 'names', 'descriptions')
|
||||||
|
|
||||||
|
def get_flag_names(self, obj):
|
||||||
|
|
||||||
|
item_flag = ItemFlagDescription.objects.filter(item_flag_id=obj)
|
||||||
|
serializer = ItemFlagDescriptionSerializer(item_flag, many=True, context=self.context)
|
||||||
|
data = serializer.data
|
||||||
|
|
||||||
|
print data
|
||||||
|
|
||||||
|
for flag in data:
|
||||||
|
del flag['description']
|
||||||
|
|
||||||
|
return data
|
||||||
|
|
||||||
|
def get_flag_descriptions(self, obj):
|
||||||
|
|
||||||
|
item_flag = ItemFlagDescription.objects.filter(item_flag_id=obj)
|
||||||
|
serializer = ItemFlagDescriptionSerializer(item_flag, many=True, context=self.context)
|
||||||
|
data = serializer.data
|
||||||
|
|
||||||
|
for flag in data:
|
||||||
|
del flag['name']
|
||||||
|
|
||||||
|
return data
|
||||||
|
|
||||||
|
|
||||||
|
class ItemFlagMapSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
|
attribute = ItemFlagSummarySerializer(source='item_flag')
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = ItemFlagMap
|
||||||
|
fields = ('attribute',)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
###########################
|
||||||
|
# ITEM FLAG SERIALIZERS #
|
||||||
|
###########################
|
||||||
|
|
||||||
|
class ItemFlingEffectDescriptionSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
|
language = LanguageSummarySerializer()
|
||||||
|
description = serializers.CharField(source="effect")
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = ItemFlingEffectDescription
|
||||||
|
fields = ('description', 'language')
|
||||||
|
|
||||||
|
|
||||||
|
class ItemFlingEffectSummarySerializer(serializers.HyperlinkedModelSerializer):
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = ItemFlingEffect
|
||||||
|
fields = ('name', 'url')
|
||||||
|
|
||||||
|
|
||||||
|
class ItemFlingEffectDetailSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
|
descriptions = ItemCategoryNameSerializer(many=True, read_only=True, source="itemflingeffectdescription")
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = ItemFlingEffect
|
||||||
|
fields = ('id', 'name', 'descriptions')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#######################
|
||||||
|
# ITEM SERIALIZERS #
|
||||||
|
#######################
|
||||||
|
|
||||||
|
class ItemFlavorTextSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
|
text = serializers.CharField(source="flavor_text")
|
||||||
|
language = LanguageSummarySerializer()
|
||||||
|
version_group = VersionGroupSummarySerializer()
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = ItemFlavorText
|
||||||
|
fields = ('text', 'version_group', 'language')
|
||||||
|
|
||||||
|
|
||||||
|
class ItemDescriptionSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
|
language = LanguageSummarySerializer()
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = ItemDescription
|
||||||
|
fields = ('effect', 'short_effect', 'language')
|
||||||
|
|
||||||
|
|
||||||
|
class ItemNameSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
|
language = LanguageSummarySerializer()
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = ItemName
|
||||||
|
fields = ('name', 'language')
|
||||||
|
|
||||||
|
|
||||||
|
class ItemSummarySerializer(serializers.HyperlinkedModelSerializer):
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = Item
|
||||||
|
fields = ('name', 'url')
|
||||||
|
|
||||||
|
|
||||||
|
class ItemDetailSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
|
names = ItemNameSerializer(many=True, read_only=True, source="itemname")
|
||||||
|
descriptions = ItemDescriptionSerializer(many=True, read_only=True, source="itemdescription")
|
||||||
|
flavor_text_entries = ItemFlavorTextSerializer(many=True, read_only=True, source="itemflavortext")
|
||||||
|
category = ItemCategorySummarySerializer(source="item_category")
|
||||||
|
attributes = ItemFlagMapSerializer(many=True, read_only=True, source="itemflagmap")
|
||||||
|
fling_effect = ItemFlingEffectSummarySerializer(source="item_fling_effect")
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = Item
|
||||||
|
fields = (
|
||||||
|
'id',
|
||||||
|
'name',
|
||||||
|
'cost',
|
||||||
|
'fling_power',
|
||||||
|
'fling_effect',
|
||||||
|
'category',
|
||||||
|
'attributes',
|
||||||
|
'names',
|
||||||
|
'descriptions',
|
||||||
|
'flavor_text_entries'
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#######################
|
||||||
|
# BERRY SERIALIZERS #
|
||||||
|
#######################
|
||||||
|
|
||||||
|
class BerrySummarySerializer(serializers.HyperlinkedModelSerializer):
|
||||||
|
|
||||||
|
# name = serializers.SerializerMethodField('get_berry_name')
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = Berry
|
||||||
|
fields = ('url',)
|
||||||
|
|
||||||
|
# def get_berry_name(self,obj):
|
||||||
|
|
||||||
|
# item = Item.objects.filter(item_id=obj)
|
||||||
|
# serializer = MoveDamageClassDescriptionSerializer(move_methods, many=True, context=self.context)
|
||||||
|
# data = serializer.data
|
||||||
|
|
||||||
|
# return 'name'
|
||||||
|
|
||||||
|
|
||||||
|
class BerryDetailSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
|
item = ItemSummarySerializer()
|
||||||
|
name = serializers.SerializerMethodField('get_berry_name')
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = Berry
|
||||||
|
|
||||||
|
def get_berry_name(self,obj):
|
||||||
|
|
||||||
|
print self.fields['item'].fields['name']
|
||||||
|
# print self['item']
|
||||||
|
|
||||||
|
# item = Item.objects.filter(item_id=obj)
|
||||||
|
# serializer = MoveDamageClassDescriptionSerializer(move_methods, many=True, context=self.context)
|
||||||
|
# data = serializer.data
|
||||||
|
|
||||||
|
return 'name'
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
###########################
|
||||||
|
# EGG GROUP SERIALIZERS #
|
||||||
|
###########################
|
||||||
|
|
||||||
|
class EggGroupNameSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
|
language = LanguageSummarySerializer()
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = EggGroupName
|
||||||
|
fields = ('name', 'language')
|
||||||
|
|
||||||
|
|
||||||
|
class EggGroupSummarySerializer(serializers.HyperlinkedModelSerializer):
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = EggGroup
|
||||||
|
fields = ('name', 'url')
|
||||||
|
|
||||||
|
|
||||||
|
class EggGroupDetailSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
|
names = EggGroupNameSerializer(many=True, read_only=True, source="egggroupname")
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = EggGroup
|
||||||
|
fields = ('id', 'name', 'names')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
######################
|
######################
|
||||||
# TYPE SERIALIZERS #
|
# TYPE SERIALIZERS #
|
||||||
######################
|
######################
|
||||||
|
@ -612,6 +914,35 @@ class PokemonFormSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#################################
|
||||||
|
# POKEMON HABITAT SERIALIZERS #
|
||||||
|
#################################
|
||||||
|
|
||||||
|
class PokemonHabitatNameSerializer(serializers.HyperlinkedModelSerializer):
|
||||||
|
|
||||||
|
language = LanguageSummarySerializer()
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = PokemonHabitatName
|
||||||
|
fields = ('name', 'language')
|
||||||
|
|
||||||
|
|
||||||
|
class PokemonHabitatSummarySerializer(serializers.HyperlinkedModelSerializer):
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = PokemonHabitat
|
||||||
|
fields = ('name', 'url')
|
||||||
|
|
||||||
|
|
||||||
|
class PokemonHabitatDetailSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
|
names = PokemonHabitatNameSerializer(many=True, read_only=True, source="pokemonhabitatname")
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = PokemonHabitat
|
||||||
|
fields = ('id', 'name', 'names')
|
||||||
|
|
||||||
|
|
||||||
##############################
|
##############################
|
||||||
# POKEMON MOVE SERIALIZERS #
|
# POKEMON MOVE SERIALIZERS #
|
||||||
##############################
|
##############################
|
||||||
|
@ -716,92 +1047,6 @@ class PokemonShapeDetailSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#################################
|
|
||||||
# POKEMON SPECIES SERIALIZERS #
|
|
||||||
#################################
|
|
||||||
|
|
||||||
class PokemonSpeciesNameSerializer(serializers.ModelSerializer):
|
|
||||||
|
|
||||||
language = LanguageSummarySerializer()
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = PokemonSpeciesName
|
|
||||||
fields = ('name', 'genus', 'language')
|
|
||||||
|
|
||||||
|
|
||||||
class PokemonSpeciesSummarySerializer(serializers.HyperlinkedModelSerializer):
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = PokemonSpecies
|
|
||||||
fields = ('name', 'url')
|
|
||||||
|
|
||||||
|
|
||||||
class PokemonSpeciesDetailSerializer(serializers.ModelSerializer):
|
|
||||||
|
|
||||||
names = serializers.SerializerMethodField('get_pokemon_names')
|
|
||||||
genera = serializers.SerializerMethodField('get_pokemon_genera')
|
|
||||||
generation = GenerationSummarySerializer()
|
|
||||||
growth_rate = GrowthRateSummarySerializer()
|
|
||||||
pokemon_color = PokemonColorSummarySerializer()
|
|
||||||
pokemon_shape = PokemonShapeSummarySerializer()
|
|
||||||
# varieties = PokemonDetailSerializer(many=True, read_only=True, source="pokemon")
|
|
||||||
# types = TypeSummarySerializer(many=True, read_only=True, source="pokemonspecies")
|
|
||||||
|
|
||||||
class Meta:
|
|
||||||
model = PokemonSpecies
|
|
||||||
fields = (
|
|
||||||
'id',
|
|
||||||
'name',
|
|
||||||
'order',
|
|
||||||
'gender_rate',
|
|
||||||
'capture_rate',
|
|
||||||
'base_happiness',
|
|
||||||
'is_baby',
|
|
||||||
'hatch_counter',
|
|
||||||
'has_gender_differences',
|
|
||||||
'forms_switchable',
|
|
||||||
'growth_rate',
|
|
||||||
'pokemon_color',
|
|
||||||
'pokemon_shape',
|
|
||||||
'evolves_from_species',
|
|
||||||
'evolution_chain',
|
|
||||||
'pokemon_habitat',
|
|
||||||
'generation',
|
|
||||||
# 'types',
|
|
||||||
'names',
|
|
||||||
'genera',
|
|
||||||
# 'varieties'
|
|
||||||
)
|
|
||||||
|
|
||||||
def get_pokemon_names(self, obj):
|
|
||||||
|
|
||||||
results = PokemonSpeciesName.objects.filter(pokemon_species=obj)
|
|
||||||
serializer = PokemonSpeciesNameSerializer(results, many=True, context=self.context)
|
|
||||||
data = serializer.data
|
|
||||||
|
|
||||||
for name in data:
|
|
||||||
del name['genus']
|
|
||||||
|
|
||||||
return data
|
|
||||||
|
|
||||||
def get_pokemon_genera(self, obj):
|
|
||||||
|
|
||||||
results = PokemonSpeciesName.objects.filter(pokemon_species=obj)
|
|
||||||
serializer = PokemonSpeciesNameSerializer(results, many=True, context=self.context)
|
|
||||||
data = serializer.data
|
|
||||||
genera = []
|
|
||||||
|
|
||||||
for entry in data:
|
|
||||||
if entry['genus']:
|
|
||||||
del entry['name']
|
|
||||||
genera.append(entry)
|
|
||||||
|
|
||||||
return genera
|
|
||||||
|
|
||||||
# def get_pokemon_types()
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
##############################
|
##############################
|
||||||
# POKEMON STAT SERIALIZERS #
|
# POKEMON STAT SERIALIZERS #
|
||||||
##############################
|
##############################
|
||||||
|
@ -856,11 +1101,13 @@ class PokemonDetailSerializer(serializers.ModelSerializer):
|
||||||
types = PokemonTypeSerializer(many=True, read_only=True, source="pokemontype")
|
types = PokemonTypeSerializer(many=True, read_only=True, source="pokemontype")
|
||||||
# forms = PokemonFormSerializer(many=True, read_only=True, source="pokemonform")
|
# forms = PokemonFormSerializer(many=True, read_only=True, source="pokemonform")
|
||||||
|
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Pokemon
|
model = Pokemon
|
||||||
fields = (
|
fields = (
|
||||||
'id',
|
'id',
|
||||||
'order',
|
'order',
|
||||||
|
'pokemon_species',
|
||||||
'name',
|
'name',
|
||||||
'is_default',
|
'is_default',
|
||||||
'height',
|
'height',
|
||||||
|
@ -919,15 +1166,116 @@ class PokemonDetailSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
#################################
|
||||||
|
# POKEMON SPECIES SERIALIZERS #
|
||||||
|
#################################
|
||||||
|
|
||||||
|
class PokemonEvolutionSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = PokemonEvolution
|
||||||
|
|
||||||
|
|
||||||
|
class PokemonSpeciesNameSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
|
language = LanguageSummarySerializer()
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = PokemonSpeciesName
|
||||||
|
fields = ('name', 'genus', 'language')
|
||||||
|
|
||||||
|
|
||||||
|
class PokemonSpeciesSummarySerializer(serializers.HyperlinkedModelSerializer):
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = PokemonSpecies
|
||||||
|
fields = ('name', 'url')
|
||||||
|
|
||||||
|
|
||||||
|
class PokemonSpeciesDetailSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
|
names = serializers.SerializerMethodField('get_pokemon_names')
|
||||||
|
genera = serializers.SerializerMethodField('get_pokemon_genera')
|
||||||
|
generation = GenerationSummarySerializer()
|
||||||
|
growth_rate = GrowthRateSummarySerializer()
|
||||||
|
color = PokemonColorSummarySerializer(source="pokemon_color")
|
||||||
|
habitat = PokemonHabitatSummarySerializer(source="pokemon_habitat")
|
||||||
|
shape = PokemonShapeSummarySerializer(source="pokemon_shape")
|
||||||
|
evolves_from_species = PokemonSpeciesSummarySerializer()
|
||||||
|
varieties = PokemonSummarySerializer(many=True, read_only=True, source="pokemon")
|
||||||
|
evolution_chain = serializers.SerializerMethodField('get_evolutions')
|
||||||
|
|
||||||
|
class Meta:
|
||||||
|
model = PokemonSpecies
|
||||||
|
fields = (
|
||||||
|
'id',
|
||||||
|
'name',
|
||||||
|
'order',
|
||||||
|
'gender_rate',
|
||||||
|
'capture_rate',
|
||||||
|
'base_happiness',
|
||||||
|
'is_baby',
|
||||||
|
'hatch_counter',
|
||||||
|
'has_gender_differences',
|
||||||
|
'forms_switchable',
|
||||||
|
'growth_rate',
|
||||||
|
'color',
|
||||||
|
'shape',
|
||||||
|
'evolves_from_species',
|
||||||
|
'evolution_chain',
|
||||||
|
'habitat',
|
||||||
|
'generation',
|
||||||
|
'names',
|
||||||
|
'genera',
|
||||||
|
'varieties'
|
||||||
|
)
|
||||||
|
|
||||||
|
def get_pokemon_names(self, obj):
|
||||||
|
|
||||||
|
results = PokemonSpeciesName.objects.filter(pokemon_species=obj)
|
||||||
|
serializer = PokemonSpeciesNameSerializer(results, many=True, context=self.context)
|
||||||
|
data = serializer.data
|
||||||
|
|
||||||
|
for name in data:
|
||||||
|
del name['genus']
|
||||||
|
|
||||||
|
return data
|
||||||
|
|
||||||
|
def get_pokemon_genera(self, obj):
|
||||||
|
|
||||||
|
results = PokemonSpeciesName.objects.filter(pokemon_species=obj)
|
||||||
|
serializer = PokemonSpeciesNameSerializer(results, many=True, context=self.context)
|
||||||
|
data = serializer.data
|
||||||
|
genera = []
|
||||||
|
|
||||||
|
for entry in data:
|
||||||
|
if entry['genus']:
|
||||||
|
del entry['name']
|
||||||
|
genera.append(entry)
|
||||||
|
|
||||||
|
return genera
|
||||||
|
|
||||||
|
def get_evolutions(self, obj):
|
||||||
|
|
||||||
|
chain_id = obj.evolution_chain.id
|
||||||
|
|
||||||
|
pokemon_objects = PokemonSpecies.objects.filter(evolution_chain_id=chain_id).order_by('order')
|
||||||
|
data = PokemonSpeciesSummarySerializer(pokemon_objects, many=True, context=self.context).data
|
||||||
|
print data
|
||||||
|
|
||||||
|
return data
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
class PokemonDexNumberSerializer(serializers.ModelSerializer):
|
class PokemonDexNumberSerializer(serializers.ModelSerializer):
|
||||||
|
|
||||||
entry_number = serializers.IntegerField(source="pokedex_number")
|
entry_number = serializers.IntegerField(source="pokedex_number")
|
||||||
pokemon = PokemonSpeciesSummarySerializer(source="pokemon_species")
|
pokemon_species = PokemonSpeciesSummarySerializer(source="pokemon_species")
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = PokemonDexNumber
|
model = PokemonDexNumber
|
||||||
fields = ('pokedex', 'entry_number', 'pokemon')
|
fields = ('pokedex', 'entry_number', 'pokemon_species')
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|
|
@ -66,6 +66,20 @@ class AbilityResource(PokeapiCommonViewset):
|
||||||
list_serializer_class = AbilitySummarySerializer
|
list_serializer_class = AbilitySummarySerializer
|
||||||
|
|
||||||
|
|
||||||
|
class BerryResource(PokeapiCommonViewset):
|
||||||
|
|
||||||
|
queryset = Berry.objects.all()
|
||||||
|
serializer_class = BerryDetailSerializer
|
||||||
|
list_serializer_class = BerrySummarySerializer
|
||||||
|
|
||||||
|
|
||||||
|
class EggGroupResource(PokeapiCommonViewset):
|
||||||
|
|
||||||
|
queryset = EggGroup.objects.all()
|
||||||
|
serializer_class = EggGroupDetailSerializer
|
||||||
|
list_serializer_class = EggGroupSummarySerializer
|
||||||
|
|
||||||
|
|
||||||
class GenerationResource(PokeapiCommonViewset):
|
class GenerationResource(PokeapiCommonViewset):
|
||||||
|
|
||||||
queryset = Generation.objects.all()
|
queryset = Generation.objects.all()
|
||||||
|
@ -80,6 +94,41 @@ class GrowthRateResource(PokeapiCommonViewset):
|
||||||
list_serializer_class = GrowthRateSummarySerializer
|
list_serializer_class = GrowthRateSummarySerializer
|
||||||
|
|
||||||
|
|
||||||
|
class ItemResource(PokeapiCommonViewset):
|
||||||
|
|
||||||
|
queryset = Item.objects.all()
|
||||||
|
serializer_class = ItemDetailSerializer
|
||||||
|
list_serializer_class = ItemSummarySerializer
|
||||||
|
|
||||||
|
|
||||||
|
class ItemCategoryResource(PokeapiCommonViewset):
|
||||||
|
|
||||||
|
queryset = ItemCategory.objects.all()
|
||||||
|
serializer_class = ItemCategoryDetailSerializer
|
||||||
|
list_serializer_class = ItemCategorySummarySerializer
|
||||||
|
|
||||||
|
|
||||||
|
class ItemFlagResource(PokeapiCommonViewset):
|
||||||
|
|
||||||
|
queryset = ItemFlag.objects.all()
|
||||||
|
serializer_class = ItemFlagDetailSerializer
|
||||||
|
list_serializer_class = ItemFlagSummarySerializer
|
||||||
|
|
||||||
|
|
||||||
|
class ItemFlingEffectResource(PokeapiCommonViewset):
|
||||||
|
|
||||||
|
queryset = ItemFlingEffect.objects.all()
|
||||||
|
serializer_class = ItemFlingEffectDetailSerializer
|
||||||
|
list_serializer_class = ItemFlingEffectSummarySerializer
|
||||||
|
|
||||||
|
|
||||||
|
class ItemPocketResource(PokeapiCommonViewset):
|
||||||
|
|
||||||
|
queryset = ItemPocket.objects.all()
|
||||||
|
serializer_class = ItemPocketDetailSerializer
|
||||||
|
list_serializer_class = ItemPocketSummarySerializer
|
||||||
|
|
||||||
|
|
||||||
class LanguageResource(PokeapiCommonViewset):
|
class LanguageResource(PokeapiCommonViewset):
|
||||||
|
|
||||||
queryset = Language.objects.all()
|
queryset = Language.objects.all()
|
||||||
|
@ -148,6 +197,13 @@ class PokemonColorResource(PokeapiCommonViewset):
|
||||||
list_serializer_class = PokemonColorSummarySerializer
|
list_serializer_class = PokemonColorSummarySerializer
|
||||||
|
|
||||||
|
|
||||||
|
class PokemonHabitatResource(PokeapiCommonViewset):
|
||||||
|
|
||||||
|
queryset = PokemonHabitat.objects.all()
|
||||||
|
serializer_class = PokemonHabitatDetailSerializer
|
||||||
|
list_serializer_class = PokemonHabitatSummarySerializer
|
||||||
|
|
||||||
|
|
||||||
class PokemonShapeResource(PokeapiCommonViewset):
|
class PokemonShapeResource(PokeapiCommonViewset):
|
||||||
|
|
||||||
queryset = PokemonShape.objects.all()
|
queryset = PokemonShape.objects.all()
|
||||||
|
@ -162,6 +218,13 @@ class PokemonResource(PokeapiCommonViewset):
|
||||||
list_serializer_class =PokemonSummarySerializer
|
list_serializer_class =PokemonSummarySerializer
|
||||||
|
|
||||||
|
|
||||||
|
class PokemonSpeciesResource(PokeapiCommonViewset):
|
||||||
|
|
||||||
|
queryset = PokemonSpecies.objects.all()
|
||||||
|
serializer_class = PokemonSpeciesDetailSerializer
|
||||||
|
list_serializer_class = PokemonSpeciesSummarySerializer
|
||||||
|
|
||||||
|
|
||||||
class RegionResource(PokeapiCommonViewset):
|
class RegionResource(PokeapiCommonViewset):
|
||||||
|
|
||||||
queryset = Region.objects.all()
|
queryset = Region.objects.all()
|
||||||
|
|
Loading…
Reference in a new issue