All checks were successful
continuous-integration/drone/push Build is passing
* More fields are now optional. This is to make it easier to add new items in bulk. * Game: Wikidata ID * Edition: Platform, Year * Purchase: Platform * Platform: Group * Session: Device * New fields: * Game: Year Released * To record original year of release * Upon migration, this will be set to a year of any of the game's edition that has it set * Purchase: Date Finished * Editions are now unique combination of name and platform
25 lines
723 B
Python
25 lines
723 B
Python
from django.db import migrations
|
|
|
|
|
|
def update_game_year(apps, schema_editor):
|
|
Game = apps.get_model("games", "Game")
|
|
Edition = apps.get_model("games", "Edition")
|
|
|
|
for game in Game.objects.filter(year__isnull=True):
|
|
# Try to get the first related edition with a non-null year_released
|
|
edition = Edition.objects.filter(game=game, year_released__isnull=False).first()
|
|
if edition:
|
|
# If an edition is found, update the game's year
|
|
game.year = edition.year_released
|
|
game.save()
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
dependencies = [
|
|
("games", "0020_game_year"),
|
|
]
|
|
|
|
operations = [
|
|
migrations.RunPython(update_game_year),
|
|
]
|