diff --git a/aiarena/core/migrations/0047_auto_20220523_0307.py b/aiarena/core/migrations/0047_auto_20220523_0307.py index 2e23fe0c..2c52d08d 100644 --- a/aiarena/core/migrations/0047_auto_20220523_0307.py +++ b/aiarena/core/migrations/0047_auto_20220523_0307.py @@ -3,23 +3,8 @@ from django.db import migrations, models import django.db.models.deletion -from aiarena.core.models import Bot -from aiarena.core.models.bot_race import BotRace - - -def link_bot_races(apps, schema_editor): - if Bot.objects.count() > 0: - BotRace.create_all_races() - - BotModel = apps.get_model('core', 'Bot') - - for bot in BotModel.objects.all(): - br = BotRace.objects.filter(label=bot.plays_race_model).first() - bot.plays_race_model = br - bot.save() class Migration(migrations.Migration): - dependencies = [ ('core', '0046_competitionbotmapstats'), ] @@ -37,5 +22,4 @@ class Migration(migrations.Migration): name='plays_race_model', field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT, to='core.botrace'), ), - migrations.RunPython(link_bot_races), ] diff --git a/aiarena/core/migrations/0048_auto_20220523_0329.py b/aiarena/core/migrations/0048_auto_20220523_0329.py index 9b1d7e75..43f9840d 100644 --- a/aiarena/core/migrations/0048_auto_20220523_0329.py +++ b/aiarena/core/migrations/0048_auto_20220523_0329.py @@ -2,16 +2,27 @@ from django.db import migrations +from aiarena.core.models import Bot +from aiarena.core.models.bot_race import BotRace -class Migration(migrations.Migration): +def link_bot_races(apps, schema_editor): + if Bot.objects.count() > 0: + BotRace.create_all_races() + + for bot in Bot.objects.all(): + br = BotRace.objects.get(label=bot.plays_race) + bot.plays_race_model_id = br.id + bot.save() + + assert Bot.objects.filter(plays_race_model=None).count() == 0 + + +class Migration(migrations.Migration): dependencies = [ ('core', '0047_auto_20220523_0307'), ] operations = [ - migrations.RemoveField( - model_name='bot', - name='plays_race', - ), + migrations.RunPython(link_bot_races), ] diff --git a/aiarena/core/migrations/0049_alter_bot_plays_race_model.py b/aiarena/core/migrations/0049_alter_bot_plays_race_model.py index d1d690ef..bf626adb 100644 --- a/aiarena/core/migrations/0049_alter_bot_plays_race_model.py +++ b/aiarena/core/migrations/0049_alter_bot_plays_race_model.py @@ -11,9 +11,9 @@ class Migration(migrations.Migration): ] operations = [ - migrations.AlterField( - model_name='bot', - name='plays_race_model', - field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='core.botrace'), - ), + # migrations.AlterField( + # model_name='bot', + # name='plays_race_model', + # field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='core.botrace'), + # ), ] diff --git a/aiarena/core/models/bot.py b/aiarena/core/models/bot.py index 2d0676c9..fc2c4d87 100644 --- a/aiarena/core/models/bot.py +++ b/aiarena/core/models/bot.py @@ -37,6 +37,12 @@ def bot_data_upload_to(instance, filename): class Bot(models.Model, LockableModelMixin): + RACES = ( + ('T', 'Terran'), + ('Z', 'Zerg'), + ('P', 'Protoss'), + ('R', 'Random'), + ) TYPES = ( # todo: update display names. capitalize etc ('cppwin32', 'cppwin32'), ('cpplinux', 'cpplinux'), @@ -69,8 +75,9 @@ class Bot(models.Model, LockableModelMixin): blank=True, null=True) bot_data_md5hash = models.CharField(max_length=32, editable=False, null=True) bot_data_publicly_downloadable = models.BooleanField(default=False) + plays_race = models.CharField(max_length=1, choices=RACES) # todo: rename back to plays_race - plays_race_model = models.ForeignKey(BotRace, on_delete=models.PROTECT) + plays_race_model = models.ForeignKey(BotRace, on_delete=models.PROTECT, null=True) type = models.CharField(max_length=32, choices=TYPES) # the ID displayed to other bots during a game so they can recognize their opponent game_display_id = models.UUIDField(default=uuid.uuid4)