mirror of
https://github.com/PokeAPI/pokeapi
synced 2025-02-16 12:38:25 +00:00
inital rest_framework progress
This commit is contained in:
parent
7555ad779d
commit
9adcec8eac
5 changed files with 184 additions and 9 deletions
|
@ -11,6 +11,8 @@ ADMINS = (
|
|||
('Paul Hallett', 'paulandrewhallett@gmail.com'),
|
||||
)
|
||||
|
||||
BASE_URL = 'http://pokeapi.co'
|
||||
|
||||
MANAGERS = ADMINS
|
||||
|
||||
# Hosts/domain names that are valid for this site; required if DEBUG is False
|
||||
|
|
|
@ -1,4 +0,0 @@
|
|||
from __future__ import unicode_literals
|
||||
from django.contrib import admin
|
||||
|
||||
# Register your models here.
|
|
@ -1,4 +0,0 @@
|
|||
from __future__ import unicode_literals
|
||||
from django.db import models
|
||||
|
||||
# Create your models here.
|
181
pokemon_v2/serializers.py
Normal file
181
pokemon_v2/serializers.py
Normal file
|
@ -0,0 +1,181 @@
|
|||
from __future__ import unicode_literals
|
||||
"""
|
||||
PokeAPI v2 serializers
|
||||
"""
|
||||
|
||||
from urlparse import urljoin
|
||||
|
||||
from rest_framework import serializers
|
||||
|
||||
from config.settings import BASE_URL
|
||||
|
||||
from pokemon.models import (
|
||||
Ability,
|
||||
EggGroup,
|
||||
Game,
|
||||
Move,
|
||||
Pokemon,
|
||||
Pokedex,
|
||||
Sprite,
|
||||
Type
|
||||
)
|
||||
|
||||
|
||||
|
||||
class PokemonSerializer(serializers.HyperlinkedModelSerializer):
|
||||
"""
|
||||
Serializer for the Pokemon resource
|
||||
"""
|
||||
|
||||
class Meta:
|
||||
model = Pokemon
|
||||
fields = (
|
||||
'name',
|
||||
'pkdx_id'
|
||||
'species',
|
||||
'height',
|
||||
'weight',
|
||||
'ev_yield',
|
||||
'catch_rate',
|
||||
'happiness',
|
||||
'exp',
|
||||
'growth_rate',
|
||||
'male_female_ratio',
|
||||
'hp',
|
||||
'attack',
|
||||
'defense',
|
||||
'sp_atk',
|
||||
'sp_def',
|
||||
'speed',
|
||||
'total',
|
||||
'egg_cycles',
|
||||
'abilities',
|
||||
'types',
|
||||
'evolutions', # Will need some hacking
|
||||
'egg_group',
|
||||
'descriptions',
|
||||
'sprites',
|
||||
'moves',
|
||||
'modified',
|
||||
'created',
|
||||
)
|
||||
|
||||
|
||||
class PokedexSerializer(serializers.HyperlinkedModelSerializer):
|
||||
"""
|
||||
Serializer for the Pokedex resource
|
||||
"""
|
||||
|
||||
class Meta:
|
||||
model = Pokedex
|
||||
fields = (
|
||||
'name',
|
||||
'pokemon',
|
||||
'modified',
|
||||
'created',
|
||||
)
|
||||
|
||||
|
||||
class SpriteSerializer(serializers.HyperlinkedModelSerializer):
|
||||
"""
|
||||
Serializer for the Sprite resource
|
||||
"""
|
||||
|
||||
image = serializers.SerializerMethodField()
|
||||
|
||||
def get_image(self, obj):
|
||||
return urljoin(BASE_URL, obj.image.url)
|
||||
|
||||
class Meta:
|
||||
model = Sprite
|
||||
fields = (
|
||||
'name',
|
||||
'image',
|
||||
'modified',
|
||||
'created',
|
||||
)
|
||||
|
||||
|
||||
class AbilitySerializer(serializers.HyperlinkedModelSerializer):
|
||||
"""
|
||||
Serializer for the Ability resource
|
||||
"""
|
||||
|
||||
class Meta:
|
||||
model = Ability
|
||||
fields = (
|
||||
'name',
|
||||
'description',
|
||||
'modified',
|
||||
'created',
|
||||
)
|
||||
|
||||
|
||||
class TypeSerializer(serializers.HyperlinkedModelSerializer):
|
||||
"""
|
||||
Serializer for the Type resource
|
||||
"""
|
||||
|
||||
class Meta:
|
||||
model = Type
|
||||
fields = (
|
||||
'name',
|
||||
'weaknesses',
|
||||
'resistances',
|
||||
'supers',
|
||||
'ineffectives',
|
||||
'no_effects',
|
||||
'modified',
|
||||
'created',
|
||||
)
|
||||
|
||||
|
||||
class GameSerializer(serializers.HyperlinkedModelSerializer):
|
||||
"""
|
||||
Serializer for the Game resource
|
||||
"""
|
||||
|
||||
class Meta:
|
||||
model = Game
|
||||
fields = (
|
||||
'name',
|
||||
'generation',
|
||||
'release_year',
|
||||
'modified',
|
||||
'created',
|
||||
)
|
||||
|
||||
|
||||
class EggGroupSerializer(serializers.HyperlinkedModelSerializer):
|
||||
"""
|
||||
Serializer for the Egg resource
|
||||
"""
|
||||
|
||||
class Meta:
|
||||
model = EggGroup
|
||||
fields = (
|
||||
'name',
|
||||
'pokemon',
|
||||
'modified',
|
||||
'created',
|
||||
)
|
||||
|
||||
|
||||
class MoveSerializer(serializers.HyperlinkedModelSerializer):
|
||||
"""
|
||||
Serializer for the Move resource
|
||||
"""
|
||||
|
||||
class Meta:
|
||||
model = Move
|
||||
fields = (
|
||||
'name',
|
||||
'description',
|
||||
'etype',
|
||||
'pp',
|
||||
'category',
|
||||
'power',
|
||||
'accuracy',
|
||||
'modified',
|
||||
'created',
|
||||
)
|
|
@ -8,7 +8,7 @@ django-cors-headers==1.0.0
|
|||
django-discover-runner==0.4
|
||||
django-imagekit==3.2.4
|
||||
django-tastypie==0.12.1
|
||||
djangorestframework==3.0.0
|
||||
djangorestframework>=3.0.0
|
||||
gunicorn==0.17.0
|
||||
mimeparse==0.1.3
|
||||
pilkit==1.1.12
|
||||
|
|
Loading…
Add table
Reference in a new issue