Remove order column from Generation model and use ID column instead

This commit is contained in:
Julian Lawrance 2021-07-19 19:00:40 +01:00
parent 98eef4d482
commit 206af8a6fd
6 changed files with 15 additions and 26 deletions

View file

@ -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)

View file

@ -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

1 id main_region_id identifier order
2 1 1 generation-i 1
3 2 2 generation-ii 2
4 3 3 generation-iii 3
5 4 4 generation-iv 4
6 5 5 generation-v 5
7 6 6 generation-vi 6
8 7 7 generation-vii 7
9 8 8 generation-viii 8

View file

@ -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,
),
]

View file

@ -747,8 +747,6 @@ class Generation(HasName):
on_delete=models.CASCADE,
)
order = models.IntegerField()
class GenerationName(IsName, HasGeneration):
pass

View file

@ -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):

View file

@ -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)