Pokedex resources. Getting closer to Pokemon resources

This commit is contained in:
Zane Adickes 2015-09-15 08:26:47 -04:00
parent c958ed9999
commit 3b8b1a6cf0
10 changed files with 781 additions and 29 deletions

7
.bash_profile Normal file
View file

@ -0,0 +1,7 @@
parse_git_branch() {
git branch 2> /dev/null | sed -e '/^[^*]/d' -e 's/* \(.*\)/ (\1)/'
}
export PS1="[\W]\[\033[32m\]\$(parse_git_branch)\[\033[00m\] $ "

View file

@ -89,7 +89,7 @@ DATABASES = {
'default': {
'ENGINE': 'django.db.backends.postgresql_psycopg2',
'NAME': 'pokeapi_co_db',
'USER': 'root',
'USER': 'zane',
'PASSWORD': 'pokeapi',
'HOST': 'localhost',
'PORT': '',

View file

@ -52,6 +52,7 @@ router.register(r"generation", GenerationResource)
router.register(r"language", LanguageResource)
router.register(r"move", MoveResource)
router.register(r"nature", NatureResource)
router.register(r"pokedex", PokedexResource)
router.register(r"pokemon", PokemonResource)
router.register(r"region", RegionResource)
router.register(r"type", TypeResource)

View file

@ -730,8 +730,8 @@ for index, info in enumerate(data):
if index > 0:
typeEfficacy = TypeEfficacy (
damage_type_id = Type.objects.get(pk = int(info[0])),
target_type_id = Type.objects.get(pk = int(info[1])),
damage_type = Type.objects.get(pk = int(info[0])),
target_type = Type.objects.get(pk = int(info[1])),
damage_factor = int(info[2])
)
typeEfficacy.save()

View file

@ -0,0 +1,554 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('pokemon_v2', '0001_squashed_0006_auto_20150910_0357'),
]
operations = [
migrations.AlterField(
model_name='ability',
name='generation',
field=models.ForeignKey(related_name='ability', blank=True, to='pokemon_v2.Generation', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='abilitychangedescription',
name='language',
field=models.ForeignKey(related_name='abilitychangedescription_language', blank=True, to='pokemon_v2.Language', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='abilitydescription',
name='language',
field=models.ForeignKey(related_name='abilitydescription_language', blank=True, to='pokemon_v2.Language', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='abilityflavortext',
name='language',
field=models.ForeignKey(related_name='abilityflavortext_language', blank=True, to='pokemon_v2.Language', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='abilityflavortext',
name='version_group',
field=models.ForeignKey(related_name='abilityflavortext', blank=True, to='pokemon_v2.VersionGroup', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='abilityname',
name='language',
field=models.ForeignKey(related_name='abilityname_language', blank=True, to='pokemon_v2.Language', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='berryfirmnessname',
name='language',
field=models.ForeignKey(related_name='berryfirmnessname_language', blank=True, to='pokemon_v2.Language', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='characteristicdescription',
name='language',
field=models.ForeignKey(related_name='characteristicdescription_language', blank=True, to='pokemon_v2.Language', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='contesteffectdescription',
name='language',
field=models.ForeignKey(related_name='contesteffectdescription_language', blank=True, to='pokemon_v2.Language', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='contesttypename',
name='language',
field=models.ForeignKey(related_name='contesttypename_language', blank=True, to='pokemon_v2.Language', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='egggroupname',
name='language',
field=models.ForeignKey(related_name='egggroupname_language', blank=True, to='pokemon_v2.Language', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='encounter',
name='version',
field=models.ForeignKey(related_name='encounter', blank=True, to='pokemon_v2.Version', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='encounterconditionname',
name='language',
field=models.ForeignKey(related_name='encounterconditionname_language', blank=True, to='pokemon_v2.Language', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='encounterconditionvaluename',
name='language',
field=models.ForeignKey(related_name='encounterconditionvaluename_language', blank=True, to='pokemon_v2.Language', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='encountermethodname',
name='language',
field=models.ForeignKey(related_name='encountermethodname_language', blank=True, to='pokemon_v2.Language', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='encounterslot',
name='version_group',
field=models.ForeignKey(related_name='encounterslot', blank=True, to='pokemon_v2.VersionGroup', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='evolutiontriggername',
name='language',
field=models.ForeignKey(related_name='evolutiontriggername_language', blank=True, to='pokemon_v2.Language', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='generation',
name='region',
field=models.ForeignKey(related_name='generation', blank=True, to='pokemon_v2.Region', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='generationname',
name='generation',
field=models.ForeignKey(related_name='generationname', blank=True, to='pokemon_v2.Generation', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='generationname',
name='language',
field=models.ForeignKey(related_name='generationname_language', blank=True, to='pokemon_v2.Language', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='growthratedescription',
name='language',
field=models.ForeignKey(related_name='growthratedescription_language', blank=True, to='pokemon_v2.Language', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='itemcategoryname',
name='language',
field=models.ForeignKey(related_name='itemcategoryname_language', blank=True, to='pokemon_v2.Language', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='itemdescription',
name='language',
field=models.ForeignKey(related_name='itemdescription_language', blank=True, to='pokemon_v2.Language', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='itemflagdescription',
name='language',
field=models.ForeignKey(related_name='itemflagdescription_language', blank=True, to='pokemon_v2.Language', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='itemflavortext',
name='language',
field=models.ForeignKey(related_name='itemflavortext_language', blank=True, to='pokemon_v2.Language', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='itemflavortext',
name='version_group',
field=models.ForeignKey(related_name='itemflavortext', blank=True, to='pokemon_v2.VersionGroup', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='itemflingeffectdescription',
name='language',
field=models.ForeignKey(related_name='itemflingeffectdescription_language', blank=True, to='pokemon_v2.Language', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='itemgameindex',
name='generation',
field=models.ForeignKey(related_name='itemgameindex', blank=True, to='pokemon_v2.Generation', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='itemname',
name='language',
field=models.ForeignKey(related_name='itemname_language', blank=True, to='pokemon_v2.Language', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='itempocketname',
name='language',
field=models.ForeignKey(related_name='itempocketname_language', blank=True, to='pokemon_v2.Language', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='languagename',
name='language',
field=models.ForeignKey(related_name='languagename_language', blank=True, to='pokemon_v2.Language', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='location',
name='region',
field=models.ForeignKey(related_name='location', blank=True, to='pokemon_v2.Region', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='locationareaencounterrate',
name='version',
field=models.ForeignKey(related_name='locationareaencounterrate', blank=True, to='pokemon_v2.Version', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='locationareaname',
name='language',
field=models.ForeignKey(related_name='locationareaname_language', blank=True, to='pokemon_v2.Language', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='locationgameindex',
name='generation',
field=models.ForeignKey(related_name='locationgameindex', blank=True, to='pokemon_v2.Generation', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='locationname',
name='language',
field=models.ForeignKey(related_name='locationname_language', blank=True, to='pokemon_v2.Language', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='move',
name='generation',
field=models.ForeignKey(related_name='move', blank=True, to='pokemon_v2.Generation', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='move',
name='type',
field=models.ForeignKey(related_name='move', blank=True, to='pokemon_v2.Type', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='movebattlestylename',
name='language',
field=models.ForeignKey(related_name='movebattlestylename_language', blank=True, to='pokemon_v2.Language', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='movechange',
name='type',
field=models.ForeignKey(related_name='movechange', blank=True, to='pokemon_v2.Type', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='movechange',
name='version_group',
field=models.ForeignKey(related_name='movechange', blank=True, to='pokemon_v2.VersionGroup', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='movedamageclassdescription',
name='language',
field=models.ForeignKey(related_name='movedamageclassdescription_language', blank=True, to='pokemon_v2.Language', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='moveeffectchange',
name='version_group',
field=models.ForeignKey(related_name='moveeffectchange', blank=True, to='pokemon_v2.VersionGroup', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='moveeffectchangedescription',
name='language',
field=models.ForeignKey(related_name='moveeffectchangedescription_language', blank=True, to='pokemon_v2.Language', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='moveeffectdescription',
name='language',
field=models.ForeignKey(related_name='moveeffectdescription_language', blank=True, to='pokemon_v2.Language', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='moveflagdescription',
name='language',
field=models.ForeignKey(related_name='moveflagdescription_language', blank=True, to='pokemon_v2.Language', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='moveflavortext',
name='language',
field=models.ForeignKey(related_name='moveflavortext_language', blank=True, to='pokemon_v2.Language', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='moveflavortext',
name='version_group',
field=models.ForeignKey(related_name='moveflavortext', blank=True, to='pokemon_v2.VersionGroup', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='movemetaailmentname',
name='language',
field=models.ForeignKey(related_name='movemetaailmentname_language', blank=True, to='pokemon_v2.Language', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='movemetacategorydescription',
name='language',
field=models.ForeignKey(related_name='movemetacategorydescription_language', blank=True, to='pokemon_v2.Language', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='movename',
name='language',
field=models.ForeignKey(related_name='movename_language', blank=True, to='pokemon_v2.Language', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='movetargetdescription',
name='language',
field=models.ForeignKey(related_name='movetargetdescription_language', blank=True, to='pokemon_v2.Language', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='naturename',
name='language',
field=models.ForeignKey(related_name='naturename_language', blank=True, to='pokemon_v2.Language', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='palparkareaname',
name='language',
field=models.ForeignKey(related_name='palparkareaname_language', blank=True, to='pokemon_v2.Language', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='pokeathlonstatname',
name='language',
field=models.ForeignKey(related_name='pokeathlonstatname_language', blank=True, to='pokemon_v2.Language', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='pokedex',
name='region',
field=models.ForeignKey(related_name='pokedex', blank=True, to='pokemon_v2.Region', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='pokedexdescription',
name='language',
field=models.ForeignKey(related_name='pokedexdescription_language', blank=True, to='pokemon_v2.Language', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='pokedexversiongroup',
name='version_group',
field=models.ForeignKey(related_name='pokedexversiongroup', blank=True, to='pokemon_v2.VersionGroup', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='pokemoncolorname',
name='language',
field=models.ForeignKey(related_name='pokemoncolorname_language', blank=True, to='pokemon_v2.Language', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='pokemonformgeneration',
name='generation',
field=models.ForeignKey(related_name='pokemonformgeneration', blank=True, to='pokemon_v2.Generation', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='pokemonformname',
name='language',
field=models.ForeignKey(related_name='pokemonformname_language', blank=True, to='pokemon_v2.Language', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='pokemongameindex',
name='version',
field=models.ForeignKey(related_name='pokemongameindex', blank=True, to='pokemon_v2.Version', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='pokemonhabitatname',
name='language',
field=models.ForeignKey(related_name='pokemonhabitatname_language', blank=True, to='pokemon_v2.Language', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='pokemonitem',
name='version',
field=models.ForeignKey(related_name='pokemonitem', blank=True, to='pokemon_v2.Version', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='pokemonmove',
name='version_group',
field=models.ForeignKey(related_name='pokemonmove', blank=True, to='pokemon_v2.VersionGroup', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='pokemonmovemethodname',
name='language',
field=models.ForeignKey(related_name='pokemonmovemethodname_language', blank=True, to='pokemon_v2.Language', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='pokemonshapename',
name='language',
field=models.ForeignKey(related_name='pokemonshapename_language', blank=True, to='pokemon_v2.Language', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='pokemonspecies',
name='generation',
field=models.ForeignKey(related_name='pokemonspecies', blank=True, to='pokemon_v2.Generation', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='pokemonspeciesdescription',
name='language',
field=models.ForeignKey(related_name='pokemonspeciesdescription_language', blank=True, to='pokemon_v2.Language', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='pokemonspeciesflavortext',
name='language',
field=models.ForeignKey(related_name='pokemonspeciesflavortext_language', blank=True, to='pokemon_v2.Language', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='pokemonspeciesflavortext',
name='version',
field=models.ForeignKey(related_name='pokemonspeciesflavortext', blank=True, to='pokemon_v2.Version', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='pokemonspeciesname',
name='language',
field=models.ForeignKey(related_name='pokemonspeciesname_language', blank=True, to='pokemon_v2.Language', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='pokemontype',
name='type',
field=models.ForeignKey(related_name='pokemontype', blank=True, to='pokemon_v2.Type', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='regionname',
name='language',
field=models.ForeignKey(related_name='regionname_language', blank=True, to='pokemon_v2.Language', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='regionname',
name='region',
field=models.ForeignKey(related_name='regionname', blank=True, to='pokemon_v2.Region', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='statname',
name='language',
field=models.ForeignKey(related_name='statname_language', blank=True, to='pokemon_v2.Language', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='supercontesteffectdescription',
name='language',
field=models.ForeignKey(related_name='supercontesteffectdescription_language', blank=True, to='pokemon_v2.Language', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='type',
name='generation',
field=models.ForeignKey(related_name='type', blank=True, to='pokemon_v2.Generation', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='typeefficacy',
name='damage_type_id',
field=models.ForeignKey(related_name='damage_type', blank=True, to='pokemon_v2.Type', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='typeefficacy',
name='target_type_id',
field=models.ForeignKey(related_name='target_type', blank=True, to='pokemon_v2.Type', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='typegameindex',
name='generation',
field=models.ForeignKey(related_name='typegameindex', blank=True, to='pokemon_v2.Generation', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='typegameindex',
name='type',
field=models.ForeignKey(related_name='typegameindex', blank=True, to='pokemon_v2.Type', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='typename',
name='language',
field=models.ForeignKey(related_name='typename_language', blank=True, to='pokemon_v2.Language', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='typename',
name='type',
field=models.ForeignKey(related_name='typename', blank=True, to='pokemon_v2.Type', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='version',
name='version_group',
field=models.ForeignKey(related_name='version', blank=True, to='pokemon_v2.VersionGroup', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='versiongroup',
name='generation',
field=models.ForeignKey(related_name='versiongroup', blank=True, to='pokemon_v2.Generation', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='versiongrouppokemonmovemethod',
name='version_group',
field=models.ForeignKey(related_name='versiongrouppokemonmovemethod', blank=True, to='pokemon_v2.VersionGroup', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='versiongroupregion',
name='region',
field=models.ForeignKey(related_name='versiongroupregion', blank=True, to='pokemon_v2.Region', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='versiongroupregion',
name='version_group',
field=models.ForeignKey(related_name='versiongroupregion', blank=True, to='pokemon_v2.VersionGroup', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='versionname',
name='language',
field=models.ForeignKey(related_name='versionname_language', blank=True, to='pokemon_v2.Language', null=True),
preserve_default=True,
),
]

View file

@ -0,0 +1,34 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('pokemon_v2', '0002_auto_20150914_1324'),
]
operations = [
migrations.RemoveField(
model_name='typeefficacy',
name='damage_type_id',
),
migrations.RemoveField(
model_name='typeefficacy',
name='target_type_id',
),
migrations.AddField(
model_name='typeefficacy',
name='damage_type',
field=models.ForeignKey(related_name='damage_type', blank=True, to='pokemon_v2.Type', null=True),
preserve_default=True,
),
migrations.AddField(
model_name='typeefficacy',
name='target_type',
field=models.ForeignKey(related_name='target_type', blank=True, to='pokemon_v2.Type', null=True),
preserve_default=True,
),
]

View file

@ -0,0 +1,74 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import models, migrations
class Migration(migrations.Migration):
dependencies = [
('pokemon_v2', '0003_auto_20150915_0055'),
]
operations = [
migrations.AlterField(
model_name='palpark',
name='pokemon_species',
field=models.ForeignKey(related_name='palpark', blank=True, to='pokemon_v2.PokemonSpecies', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='pokedexdescription',
name='pokedex',
field=models.ForeignKey(related_name='pokedexdescription', blank=True, to='pokemon_v2.Pokedex', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='pokedexversiongroup',
name='pokedex',
field=models.ForeignKey(related_name='pokedexversiongroup', blank=True, to='pokemon_v2.Pokedex', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='pokemon',
name='pokemon_species',
field=models.ForeignKey(related_name='pokemon', blank=True, to='pokemon_v2.PokemonSpecies', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='pokemondexnumber',
name='pokedex',
field=models.ForeignKey(related_name='pokemondexnumber', blank=True, to='pokemon_v2.Pokedex', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='pokemondexnumber',
name='pokemon_species',
field=models.ForeignKey(related_name='pokemondexnumber', blank=True, to='pokemon_v2.PokemonSpecies', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='pokemonegggroup',
name='pokemon_species',
field=models.ForeignKey(related_name='pokemonegggroup', blank=True, to='pokemon_v2.PokemonSpecies', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='pokemonspeciesdescription',
name='pokemon_species',
field=models.ForeignKey(related_name='pokemonspeciesdescription', blank=True, to='pokemon_v2.PokemonSpecies', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='pokemonspeciesflavortext',
name='pokemon_species',
field=models.ForeignKey(related_name='pokemonspeciesflavortext', blank=True, to='pokemon_v2.PokemonSpecies', null=True),
preserve_default=True,
),
migrations.AlterField(
model_name='pokemonspeciesname',
name='pokemon_species',
field=models.ForeignKey(related_name='pokemonspeciesname', blank=True, to='pokemon_v2.PokemonSpecies', null=True),
preserve_default=True,
),
]

View file

@ -264,7 +264,7 @@ class HasPokeathlonStat(models.Model):
class HasPokedex(models.Model):
pokedex = models.ForeignKey('Pokedex', blank=True, null=True)
pokedex = models.ForeignKey('Pokedex', blank=True, null=True, related_name="%(class)s")
class Meta:
abstract = True
@ -320,7 +320,7 @@ class HasPokemonShape(models.Model):
class HasPokemonSpecies(models.Model):
pokemon_species = models.ForeignKey('PokemonSpecies', blank=True, null=True)
pokemon_species = models.ForeignKey('PokemonSpecies', blank=True, null=True, related_name="%(class)s")
class Meta:
abstract = True
@ -513,9 +513,9 @@ class TypeGameIndex(HasType, HasGeneration, HasGameIndex):
class TypeEfficacy(models.Model):
damage_type_id = models.ForeignKey('Type', blank=True, null=True, related_name="damage_type")
damage_type = models.ForeignKey('Type', blank=True, null=True, related_name="damage_type")
target_type_id = models.ForeignKey('Type', blank=True, null=True, related_name="target_type")
target_type = models.ForeignKey('Type', blank=True, null=True, related_name="target_type")
damage_factor = models.IntegerField()

View file

@ -259,11 +259,11 @@ class TypeDetailSerializer(serializers.ModelSerializer):
relations['double_damage_from'] = []
# Damage To
results = TypeEfficacy.objects.filter(damage_type_id=obj)
results = TypeEfficacy.objects.filter(damage_type=obj)
serializer = TypeEfficacySerializer(results, many=True, context=self.context)
for relation in serializer.data:
type = Type.objects.get(id=relation['target_type_id'])
type = Type.objects.get(pk=relation['target_type'])
if relation['damage_factor'] == 200:
relations['double_damage_to'].append(TypeSummarySerializer(type, context=self.context).data)
elif relation['damage_factor'] == 50:
@ -272,11 +272,11 @@ class TypeDetailSerializer(serializers.ModelSerializer):
relations['no_damage_to'].append(TypeSummarySerializer(type, context=self.context).data)
# Damage From
results = TypeEfficacy.objects.filter(target_type_id=obj)
results = TypeEfficacy.objects.filter(target_type=obj)
serializer = TypeEfficacySerializer(results, many=True, context=self.context)
for relation in serializer.data:
type = Type.objects.get(id=relation['damage_type_id'])
type = Type.objects.get(pk=relation['damage_type'])
if relation['damage_factor'] == 200:
relations['double_damage_from'].append(TypeSummarySerializer(type, context=self.context).data)
elif relation['damage_factor'] == 50:
@ -289,9 +289,99 @@ class TypeDetailSerializer(serializers.ModelSerializer):
#########################
# BERRY SERIALIZERS #
# POKEMON SERIALIZERS #
#########################
class PokemonSummarySerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Pokemon
fields = ('name', 'url')
class PokemonDetailSerializer(serializers.ModelSerializer):
class Meta:
model = Pokemon
class PokemonDexNumberSerializer(serializers.ModelSerializer):
class Meta:
model = PokemonDexNumber
#########################
# POKEDEX SERIALIZERS #
#########################
class PokedexDescriptionSerializer(serializers.HyperlinkedModelSerializer):
language = LanguageSummarySerializer()
class Meta:
model = PokedexDescription
fields = ('name', 'description', 'language')
class PokedexSummarySerializer(serializers.HyperlinkedModelSerializer):
class Meta:
model = Pokedex
class PokedexDetailSerializer(serializers.ModelSerializer):
"""
Name and descriptions for pokedex are stored in a 'prose'
table so this serializer wont act like the others. Need to build
the return data manually.
"""
region = RegionSummarySerializer()
names = serializers.SerializerMethodField('get_pokedex_names')
descriptions = serializers.SerializerMethodField('get_pokedex_descriptions')
# pokemon = PokemonDexNumberSerializer(many=True, read_only=True, source="pokedex")
pokemon = serializers.SerializerMethodField('get_pokedex_entries')
class Meta:
model = Pokedex
fields = ('id', 'name', 'is_main_series', 'region', 'names', 'descriptions', 'pokemon')
def get_pokedex_names(self, obj):
results = PokedexDescription.objects.filter(pokedex_id=obj)
serializer = PokedexDescriptionSerializer(results, many=True, context=self.context)
data = serializer.data
for name in data:
del name['description']
return data
def get_pokedex_descriptions(self, obj):
results = PokedexDescription.objects.filter(pokedex_id=obj)
serializer = PokedexDescriptionSerializer(results, many=True, context=self.context)
data = serializer.data
for name in data:
del name['name']
return data
def get_pokedex_entries(self, obj):
results = PokemonDexNumber.objects.filter(pokedex=obj)
serializer = PokemonDexNumberSerializer(results, many=True, context=self.context)
return serializer.data
#######################
# BERRY SERIALIZERS #
#######################
class BerrySerializer(serializers.ModelSerializer):
"""
Serializer for the Berry resource
@ -370,19 +460,3 @@ class NatureSerializer(serializers.ModelSerializer):
"""
class Meta:
model = Nature
class PokedexSerializer(serializers.ModelSerializer):
"""
Serializer for the Pokedex resource
"""
class Meta:
model = Pokedex
class PokemonSerializer(serializers.ModelSerializer):
"""
Serializer for the Pokemon resource
"""
class Meta:
model = Pokemon

View file

@ -90,10 +90,18 @@ class NatureResource(PokeapiCommonViewset):
serializer_class = NatureSerializer
class PokedexResource(PokeapiCommonViewset):
queryset = Pokedex.objects.all()
serializer_class = PokedexDetailSerializer
list_serializer_class = PokedexSummarySerializer
class PokemonResource(PokeapiCommonViewset):
queryset = Pokemon.objects.all()
serializer_class = PokemonSerializer
serializer_class = PokemonDetailSerializer
list_serializer_class =PokemonSummarySerializer
class RegionResource(PokeapiCommonViewset):