mirror of
https://github.com/PokeAPI/pokeapi
synced 2024-11-10 06:04:18 +00:00
Remove order column from Generation model and use ID column instead
This commit is contained in:
parent
98eef4d482
commit
206af8a6fd
6 changed files with 15 additions and 26 deletions
|
@ -178,9 +178,7 @@ def _build_regions():
|
||||||
|
|
||||||
def _build_generations():
|
def _build_generations():
|
||||||
def csv_record_to_objects(info):
|
def csv_record_to_objects(info):
|
||||||
yield Generation(
|
yield Generation(id=int(info[0]), region_id=int(info[1]), name=info[2])
|
||||||
id=int(info[0]), region_id=int(info[1]), name=info[2], order=info[3]
|
|
||||||
)
|
|
||||||
|
|
||||||
build_generic((Generation,), "generations.csv", csv_record_to_objects)
|
build_generic((Generation,), "generations.csv", csv_record_to_objects)
|
||||||
|
|
||||||
|
|
|
@ -1,9 +1,9 @@
|
||||||
id,main_region_id,identifier,order
|
id,main_region_id,identifier
|
||||||
1,1,generation-i,1
|
1,1,generation-i
|
||||||
2,2,generation-ii,2
|
2,2,generation-ii
|
||||||
3,3,generation-iii,3
|
3,3,generation-iii
|
||||||
4,4,generation-iv,4
|
4,4,generation-iv
|
||||||
5,5,generation-v,5
|
5,5,generation-v
|
||||||
6,6,generation-vi,6
|
6,6,generation-vi
|
||||||
7,7,generation-vii,7
|
7,7,generation-vii
|
||||||
8,8,generation-viii,8
|
8,8,generation-viii
|
||||||
|
|
|
|
@ -81,10 +81,4 @@ class Migration(migrations.Migration):
|
||||||
to="pokemon_v2.Type",
|
to="pokemon_v2.Type",
|
||||||
),
|
),
|
||||||
),
|
),
|
||||||
migrations.AddField(
|
|
||||||
model_name="generation",
|
|
||||||
name="order",
|
|
||||||
field=models.IntegerField(default=1),
|
|
||||||
preserve_default=False,
|
|
||||||
),
|
|
||||||
]
|
]
|
||||||
|
|
|
@ -747,8 +747,6 @@ class Generation(HasName):
|
||||||
on_delete=models.CASCADE,
|
on_delete=models.CASCADE,
|
||||||
)
|
)
|
||||||
|
|
||||||
order = models.IntegerField()
|
|
||||||
|
|
||||||
|
|
||||||
class GenerationName(IsName, HasGeneration):
|
class GenerationName(IsName, HasGeneration):
|
||||||
pass
|
pass
|
||||||
|
|
|
@ -678,7 +678,6 @@ class GenerationDetailSerializer(serializers.ModelSerializer):
|
||||||
"main_region",
|
"main_region",
|
||||||
"moves",
|
"moves",
|
||||||
"names",
|
"names",
|
||||||
"order",
|
|
||||||
"pokemon_species",
|
"pokemon_species",
|
||||||
"types",
|
"types",
|
||||||
"version_groups",
|
"version_groups",
|
||||||
|
@ -2031,7 +2030,7 @@ class TypeDetailSerializer(serializers.ModelSerializer):
|
||||||
def type_is_present(self, type, current_gen):
|
def type_is_present(self, type, current_gen):
|
||||||
type_obj = Type.objects.get(name=type["name"])
|
type_obj = Type.objects.get(name=type["name"])
|
||||||
gen_introduced = Generation.objects.get(pk=type_obj.generation.id)
|
gen_introduced = Generation.objects.get(pk=type_obj.generation.id)
|
||||||
return gen_introduced.order <= current_gen.order
|
return gen_introduced.id <= current_gen.id
|
||||||
|
|
||||||
def get_type_pokemon(self, obj):
|
def get_type_pokemon(self, obj):
|
||||||
|
|
||||||
|
|
|
@ -74,11 +74,11 @@ class APIData:
|
||||||
|
|
||||||
# Generation Data
|
# Generation Data
|
||||||
@classmethod
|
@classmethod
|
||||||
def setup_generation_data(cls, order=1, region=None, name="gen"):
|
def setup_generation_data(cls, region=None, name="gen"):
|
||||||
|
|
||||||
region = region or cls.setup_region_data(name="reg for " + name)
|
region = region or cls.setup_region_data(name="reg for " + name)
|
||||||
|
|
||||||
generation = Generation.objects.create(region=region, name=name, order=order)
|
generation = Generation.objects.create(region=region, name=name)
|
||||||
generation.save()
|
generation.save()
|
||||||
|
|
||||||
return generation
|
return generation
|
||||||
|
@ -3420,7 +3420,7 @@ class APITests(APIData, APITestCase):
|
||||||
pokemon = self.setup_pokemon_data(name="pkmn for base tp")
|
pokemon = self.setup_pokemon_data(name="pkmn for base tp")
|
||||||
pokemon_type = self.setup_pokemon_type_data(pokemon=pokemon, type=type)
|
pokemon_type = self.setup_pokemon_type_data(pokemon=pokemon, type=type)
|
||||||
|
|
||||||
generation = self.setup_generation_data(order=1, name="past gen")
|
generation = self.setup_generation_data(name="past gen")
|
||||||
|
|
||||||
no_damage_to = self.setup_type_data(
|
no_damage_to = self.setup_type_data(
|
||||||
name="no damage to tp", generation=generation
|
name="no damage to tp", generation=generation
|
||||||
|
@ -3441,7 +3441,7 @@ class APITests(APIData, APITestCase):
|
||||||
name="double damage from tp", generation=generation
|
name="double damage from tp", generation=generation
|
||||||
)
|
)
|
||||||
|
|
||||||
newer_generation = self.setup_generation_data(order=5, name="newer_generation")
|
newer_generation = self.setup_generation_data(name="newer_generation")
|
||||||
|
|
||||||
newer_type = self.setup_type_data(name="newer tp", generation=newer_generation)
|
newer_type = self.setup_type_data(name="newer tp", generation=newer_generation)
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue