diff --git a/helpdesk/teams/management/commands/import_from_srcomp.py b/helpdesk/teams/management/commands/import_from_srcomp.py index a227548..eddf170 100644 --- a/helpdesk/teams/management/commands/import_from_srcomp.py +++ b/helpdesk/teams/management/commands/import_from_srcomp.py @@ -53,6 +53,6 @@ def _import_teams(self, srcomp_url: str) -> None: ) # If not created, synchronise the pit locations. - if not created and team.pit_location.slug != team_data["location"]["name"]: + if not created and team.pit_location and team.pit_location.slug != team_data["location"]["name"]: team.pit_location = TeamPitLocation.objects.get(slug=team_data["location"]["name"]) team.save(update_fields=["pit_location"]) diff --git a/helpdesk/teams/migrations/0005_make_team_location_optional.py b/helpdesk/teams/migrations/0005_make_team_location_optional.py new file mode 100644 index 0000000..6eab5f1 --- /dev/null +++ b/helpdesk/teams/migrations/0005_make_team_location_optional.py @@ -0,0 +1,22 @@ +# Generated by Django 4.2.11 on 2024-04-10 18:14 + +import django.db.models.deletion +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("teams", "0004_add_team_comment"), + ] + + operations = [ + migrations.AlterModelOptions( + name="team", + options={"ordering": ["tla"]}, + ), + migrations.AlterField( + model_name="team", + name="pit_location", + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT, to="teams.teampitlocation"), + ), + ] diff --git a/helpdesk/teams/models.py b/helpdesk/teams/models.py index ec78998..dc12697 100644 --- a/helpdesk/teams/models.py +++ b/helpdesk/teams/models.py @@ -24,7 +24,7 @@ class Team(models.Model): ) name = models.CharField("Team Name", max_length=100) is_rookie = models.BooleanField("Is Rookie") - pit_location = models.ForeignKey(TeamPitLocation, on_delete=models.PROTECT) + pit_location = models.ForeignKey(TeamPitLocation, on_delete=models.PROTECT, null=True) class Meta: ordering = ["tla"]