mirror of
https://github.com/PokeAPI/pokeapi
synced 2024-11-24 20:33:04 +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 csv_record_to_objects(info):
|
||||
yield Generation(
|
||||
id=int(info[0]), region_id=int(info[1]), name=info[2], order=info[3]
|
||||
)
|
||||
yield Generation(id=int(info[0]), region_id=int(info[1]), name=info[2])
|
||||
|
||||
build_generic((Generation,), "generations.csv", csv_record_to_objects)
|
||||
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
id,main_region_id,identifier,order
|
||||
1,1,generation-i,1
|
||||
2,2,generation-ii,2
|
||||
3,3,generation-iii,3
|
||||
4,4,generation-iv,4
|
||||
5,5,generation-v,5
|
||||
6,6,generation-vi,6
|
||||
7,7,generation-vii,7
|
||||
8,8,generation-viii,8
|
||||
id,main_region_id,identifier
|
||||
1,1,generation-i
|
||||
2,2,generation-ii
|
||||
3,3,generation-iii
|
||||
4,4,generation-iv
|
||||
5,5,generation-v
|
||||
6,6,generation-vi
|
||||
7,7,generation-vii
|
||||
8,8,generation-viii
|
||||
|
|
|
|
@ -81,10 +81,4 @@ class Migration(migrations.Migration):
|
|||
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,
|
||||
)
|
||||
|
||||
order = models.IntegerField()
|
||||
|
||||
|
||||
class GenerationName(IsName, HasGeneration):
|
||||
pass
|
||||
|
|
|
@ -678,7 +678,6 @@ class GenerationDetailSerializer(serializers.ModelSerializer):
|
|||
"main_region",
|
||||
"moves",
|
||||
"names",
|
||||
"order",
|
||||
"pokemon_species",
|
||||
"types",
|
||||
"version_groups",
|
||||
|
@ -2031,7 +2030,7 @@ class TypeDetailSerializer(serializers.ModelSerializer):
|
|||
def type_is_present(self, type, current_gen):
|
||||
type_obj = Type.objects.get(name=type["name"])
|
||||
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):
|
||||
|
||||
|
|
|
@ -74,11 +74,11 @@ class APIData:
|
|||
|
||||
# Generation Data
|
||||
@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)
|
||||
|
||||
generation = Generation.objects.create(region=region, name=name, order=order)
|
||||
generation = Generation.objects.create(region=region, name=name)
|
||||
generation.save()
|
||||
|
||||
return generation
|
||||
|
@ -3420,7 +3420,7 @@ class APITests(APIData, APITestCase):
|
|||
pokemon = self.setup_pokemon_data(name="pkmn for base tp")
|
||||
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(
|
||||
name="no damage to tp", generation=generation
|
||||
|
@ -3441,7 +3441,7 @@ class APITests(APIData, APITestCase):
|
|||
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)
|
||||
|
||||
|
|
Loading…
Reference in a new issue