From 220e399cb2a42bd1bd21b1da7e168a0655b9c030 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Niccol=C3=B2=20Cant=C3=B9?= Date: Mon, 8 Jan 2024 10:39:33 +0100 Subject: [PATCH] add department --- metadata_catalogue/nina/admin.py | 23 +++++++++ ...002_department_project_department_group.py | 48 +++++++++++++++++++ metadata_catalogue/nina/models.py | 8 ++++ 3 files changed, 79 insertions(+) create mode 100644 metadata_catalogue/nina/migrations/0002_department_project_department_group.py diff --git a/metadata_catalogue/nina/admin.py b/metadata_catalogue/nina/admin.py index e69de29..ac6d2d4 100644 --- a/metadata_catalogue/nina/admin.py +++ b/metadata_catalogue/nina/admin.py @@ -0,0 +1,23 @@ +from django.contrib.admin import ModelAdmin, register + +from .models import Category, Department, Project, Topic + + +@register(Project) +class ProjectAdmin(ModelAdmin): + pass + + +@register(Department) +class DepartmentAdmin(ModelAdmin): + pass + + +@register(Category) +class CategoryAdmin(ModelAdmin): + pass + + +@register(Topic) +class TopicAdmin(ModelAdmin): + pass diff --git a/metadata_catalogue/nina/migrations/0002_department_project_department_group.py b/metadata_catalogue/nina/migrations/0002_department_project_department_group.py new file mode 100644 index 0000000..95b144f --- /dev/null +++ b/metadata_catalogue/nina/migrations/0002_department_project_department_group.py @@ -0,0 +1,48 @@ +# Generated by Django 4.2.8 on 2024-01-08 09:35 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + dependencies = [ + ("organizations", "0006_alter_organization_slug"), + ("nina", "0001_initial"), + ] + + operations = [ + migrations.CreateModel( + name="Department", + fields=[ + ( + "organization_ptr", + models.OneToOneField( + auto_created=True, + on_delete=django.db.models.deletion.CASCADE, + parent_link=True, + primary_key=True, + serialize=False, + to="organizations.organization", + ), + ), + ], + options={ + "verbose_name": "organization", + "verbose_name_plural": "organizations", + "ordering": ["name"], + "abstract": False, + }, + bases=("organizations.organization",), + ), + 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", + ), + ), + ] diff --git a/metadata_catalogue/nina/models.py b/metadata_catalogue/nina/models.py index fed81c2..f763a75 100644 --- a/metadata_catalogue/nina/models.py +++ b/metadata_catalogue/nina/models.py @@ -1,4 +1,5 @@ from django.db import models +from organizations.models import Organization from taggit.managers import TaggableManager from metadata_catalogue.projects.models import BaseProject @@ -13,6 +14,9 @@ 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" + ) tags = TaggableManager() @@ -32,3 +36,7 @@ class Category(models.Model): class Meta: constraints = [models.UniqueConstraint("name", name="unique category name")] + + +class Department(Organization): + pass