From 778ffbe584001fbcd5b017fe52e7f07cc844a533 Mon Sep 17 00:00:00 2001 From: Karina Kwiatek Date: Wed, 10 Apr 2024 19:16:41 +0100 Subject: [PATCH] Allow teams to not have a location Last year we had teams for Volunteers and "No Team", this lets us have that without making a location for "N/A" --- .../management/commands/import_from_srcomp.py | 2 +- .../0005_make_team_location_optional.py | 22 +++++++++++++++++++ helpdesk/teams/models.py | 2 +- 3 files changed, 24 insertions(+), 2 deletions(-) create mode 100644 helpdesk/teams/migrations/0005_make_team_location_optional.py 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"]