diff --git a/metadata_catalogue/nina/libs/harvesters.py b/metadata_catalogue/nina/libs/harvesters.py index acc1eb9..f16b0c3 100644 --- a/metadata_catalogue/nina/libs/harvesters.py +++ b/metadata_catalogue/nina/libs/harvesters.py @@ -47,7 +47,7 @@ def _process_project(project: dict): p.customer, _ = Organization.objects.get_or_create(name=project.get("customer")) for group in project.get("groups"): - p.department_group, _ = Department.objects.get_or_create( + d, _ = Department.objects.get_or_create( extid=group.get("id"), defaults={ "name": group.get("title"), @@ -55,8 +55,7 @@ def _process_project(project: dict): "description": group.get("description"), }, ) - # We expect only one department for project - break + p.departments.add(d) p.save() diff --git a/metadata_catalogue/nina/migrations/0001_initial.py b/metadata_catalogue/nina/migrations/0001_initial.py index c3d20d0..361f9c5 100644 --- a/metadata_catalogue/nina/migrations/0001_initial.py +++ b/metadata_catalogue/nina/migrations/0001_initial.py @@ -1,4 +1,4 @@ -# Generated by Django 4.2.8 on 2024-01-09 08:51 +# Generated by Django 4.2.8 on 2024-01-09 10:51 from django.db import migrations, models import django.db.models.deletion @@ -9,9 +9,9 @@ class Migration(migrations.Migration): initial = True dependencies = [ + ("taggit", "0006_rename_taggeditem_content_type_object_id_taggit_tagg_content_8fc721_idx"), ("organizations", "0006_alter_organization_slug"), ("datasets", "0006_content_valid"), - ("taggit", "0006_rename_taggeditem_content_type_object_id_taggit_tagg_content_8fc721_idx"), ] operations = [ @@ -91,14 +91,8 @@ class Migration(migrations.Migration): ), migrations.AddField( model_name="project", - name="department_group", - field=models.ForeignKey( - blank=True, - null=True, - on_delete=django.db.models.deletion.SET_NULL, - related_name="projects", - to="nina.department", - ), + name="departments", + field=models.ManyToManyField(blank=True, related_name="projects", to="nina.department"), ), migrations.AddField( model_name="project", diff --git a/metadata_catalogue/nina/models.py b/metadata_catalogue/nina/models.py index 2320df0..2caba2b 100644 --- a/metadata_catalogue/nina/models.py +++ b/metadata_catalogue/nina/models.py @@ -14,9 +14,7 @@ class Project(BaseProject): status = models.CharField(max_length=50, null=True, blank=True) category = models.ForeignKey("nina.Category", null=True, blank=True, on_delete=models.SET_NULL) topics = models.ManyToManyField("nina.Topic", blank=True) - department_group = models.ForeignKey( - "nina.Department", null=True, blank=True, on_delete=models.SET_NULL, related_name="projects" - ) + departments = models.ManyToManyField("nina.Department", blank=True, related_name="projects") customer = models.ForeignKey("datasets.Organization", blank=True, on_delete=models.SET_NULL, null=True) tags = TaggableManager()