From 453fbf91bee0e3b51020466ddf28520a56a1f6be Mon Sep 17 00:00:00 2001 From: Ross Date: Fri, 14 Nov 2025 20:53:31 +0000 Subject: [PATCH] Add ManyToMany fields for sites and subspecialty in Resource model --- ...82_resource_sites_resource_subspecialty.py | 24 ++++++++++++++++ atlas/models.py | 28 ++++++++++++++++++- 2 files changed, 51 insertions(+), 1 deletion(-) create mode 100644 atlas/migrations/0082_resource_sites_resource_subspecialty.py diff --git a/atlas/migrations/0082_resource_sites_resource_subspecialty.py b/atlas/migrations/0082_resource_sites_resource_subspecialty.py new file mode 100644 index 00000000..55d3489a --- /dev/null +++ b/atlas/migrations/0082_resource_sites_resource_subspecialty.py @@ -0,0 +1,24 @@ +# Generated by Django 5.2.7 on 2025-11-14 20:51 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('atlas', '0081_remove_normalcase_age_years_normalcase_age_days'), + ('generic', '0029_add_unique_constraint_supervisor_email'), + ] + + operations = [ + migrations.AddField( + model_name='resource', + name='sites', + field=models.ManyToManyField(blank=True, help_text='The site(s) this resource is associated with (if any).', related_name='resources', to='generic.site'), + ), + migrations.AddField( + model_name='resource', + name='subspecialty', + field=models.ManyToManyField(blank=True, help_text='Subspecialty or subspecialties this resource relates to.', to='atlas.subspecialty'), + ), + ] diff --git a/atlas/models.py b/atlas/models.py index 8d8d0a66..f499308b 100644 --- a/atlas/models.py +++ b/atlas/models.py @@ -59,6 +59,7 @@ from generic.models import ( SeriesBase, SeriesImageBase, Modality, + Site, UserUserGroup, ) @@ -1875,6 +1876,20 @@ class Resource(models.Model, AuthorMixin): help_text="Author of the resource", related_name="resources", ) + # Link resources to one or more Sites (from generic.Site) + sites = models.ManyToManyField( + 'generic.Site', + blank=True, + help_text='The site(s) this resource is associated with (if any).', + related_name='resources', + ) + + # Categorise resources by subspecialty + subspecialty = models.ManyToManyField( + Subspecialty, + blank=True, + help_text='Subspecialty or subspecialties this resource relates to.', + ) def __str__(self) -> str: return self.name @@ -1902,7 +1917,18 @@ class Resource(models.Model, AuthorMixin): else: html = self.name - return format_html("
{}{}
", self.name, mark_safe(html)) + meta = '' + if self.sites.exists(): + meta += ' Sites: ' + ', '.join([s.short_code or s.full_name for s in self.sites.all()]) + if self.subspecialty.exists(): + meta += ' Subspecialty: ' + ', '.join([str(s) for s in self.subspecialty.all()]) + + return format_html( + "
{}
{}
{}
", + self.name, + mark_safe(html), + meta, + )