From 46b54d6a412d7021670a695c16a322902aa7474b Mon Sep 17 00:00:00 2001 From: Beka Lewis Date: Wed, 12 Jul 2023 18:50:26 +0100 Subject: [PATCH] Add party nations to importer --- .../parties/migrations/0021_party_nations.py | 25 +++++++++++++++++++ wcivf/apps/parties/models.py | 13 ++++++++++ .../apps/parties/tests/test_import_parties.py | 1 + 3 files changed, 39 insertions(+) create mode 100644 wcivf/apps/parties/migrations/0021_party_nations.py diff --git a/wcivf/apps/parties/migrations/0021_party_nations.py b/wcivf/apps/parties/migrations/0021_party_nations.py new file mode 100644 index 000000000..be8a9b0a1 --- /dev/null +++ b/wcivf/apps/parties/migrations/0021_party_nations.py @@ -0,0 +1,25 @@ +# Generated by Django 4.1.6 on 2023-07-14 13:06 + +import django.contrib.postgres.fields +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("parties", "0020_party_alternative_name"), + ] + + operations = [ + migrations.AddField( + model_name="party", + name="nations", + field=django.contrib.postgres.fields.ArrayField( + base_field=models.CharField(max_length=3), + help_text='\n Some subset of ["ENG", "SCO", "WAL"],\n depending on where the party fields candidates. \n Nullable as not applicable to NI-based parties.\n ', + max_length=3, + null=True, + size=None, + verbose_name="Party nations", + ), + ), + ] diff --git a/wcivf/apps/parties/models.py b/wcivf/apps/parties/models.py index 37fc19d1f..12840f604 100644 --- a/wcivf/apps/parties/models.py +++ b/wcivf/apps/parties/models.py @@ -3,6 +3,7 @@ from django.utils import timezone from django.utils.text import slugify from django.utils.translation import get_language +from django.contrib.postgres.fields import ArrayField from model_utils.models import TimeStampedModel from elections.models import Election @@ -18,6 +19,7 @@ def update_or_create_from_ynr(self, party): "date_registered": party["date_registered"], "date_deregistered": party["date_deregistered"], "alternative_name": party["alternative_name"], + "nations": party["nations"], } if party["default_emblem"]: @@ -73,6 +75,17 @@ class Party(models.Model): ], default="Registered", ) + nations = ArrayField( + models.CharField(max_length=3), + max_length=3, + null=True, + verbose_name="Party nations", + help_text=""" + Some subset of ["ENG", "WAL", "SCO"], + depending on where the party fields candidates. + Nullable as not applicable to NI-based parties. + """, + ) date_registered = models.DateField(null=True) date_deregistered = models.DateField(null=True) diff --git a/wcivf/apps/parties/tests/test_import_parties.py b/wcivf/apps/parties/tests/test_import_parties.py index c09318fc6..1a308d35a 100644 --- a/wcivf/apps/parties/tests/test_import_parties.py +++ b/wcivf/apps/parties/tests/test_import_parties.py @@ -14,6 +14,7 @@ "alternative_name": "Cynghrair Wombles", "register": "GB", "status": "Registered", + "nations": ["ENG", "WAL", "SCO"], "date_registered": "2018-01-31", "date_deregistered": null, "default_emblem": {