"""Populate TarotCard.reversal for Earthman Middle Arcana court cards. Each suit has a fixed reversal qualifier that replaces the polarity qualifier (Elevated/Graven) when the card is spun to its reversed face: Brands → Seething Grails → Gloomy Blades → Nervous Crowns → Vacant Also clears the incorrectly inherited reversal on The Schizo (card 1), which mistakenly carried 'Territoriality' from The Occultist (card 2). """ from django.db import migrations SUIT_REVERSAL_QUALIFIER = { "BRANDS": "Seething", "GRAILS": "Gloomy", "BLADES": "Nervous", "CROWNS": "Vacant", } RANK_NAMES = {11: "Maid", 12: "Jack", 13: "Queen", 14: "King"} def populate_reversals(apps, schema_editor): TarotCard = apps.get_model("epic", "TarotCard") DeckVariant = apps.get_model("epic", "DeckVariant") try: earthman = DeckVariant.objects.get(slug="earthman") except DeckVariant.DoesNotExist: return # Middle Arcana court cards for suit, qualifier in SUIT_REVERSAL_QUALIFIER.items(): TarotCard.objects.filter( deck_variant=earthman, arcana="MIDDLE", suit=suit, number__in=list(RANK_NAMES.keys()), ).update(reversal=qualifier) # Clear The Schizo's incorrectly inherited reversal (belongs to The Occultist) TarotCard.objects.filter( deck_variant=earthman, arcana="MAJOR", number=1, ).update(reversal="") def clear_reversals(apps, schema_editor): TarotCard = apps.get_model("epic", "TarotCard") DeckVariant = apps.get_model("epic", "DeckVariant") try: earthman = DeckVariant.objects.get(slug="earthman") except DeckVariant.DoesNotExist: return TarotCard.objects.filter( deck_variant=earthman, arcana="MIDDLE", suit__in=list(SUIT_REVERSAL_QUALIFIER.keys()), number__in=list(RANK_NAMES.keys()), ).update(reversal="") TarotCard.objects.filter(deck_variant=earthman, arcana="MAJOR", number=1).update( reversal="Territoriality" ) class Migration(migrations.Migration): dependencies = [ ("epic", "0006_add_deck_variant_to_tableseat"), ] operations = [ migrations.RunPython(populate_reversals, reverse_code=clear_reversals), ]