Add ManyToMany fields for sites and subspecialty in Resource model
This commit is contained in:
@@ -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'),
|
||||||
|
),
|
||||||
|
]
|
||||||
+27
-1
@@ -59,6 +59,7 @@ from generic.models import (
|
|||||||
SeriesBase,
|
SeriesBase,
|
||||||
SeriesImageBase,
|
SeriesImageBase,
|
||||||
Modality,
|
Modality,
|
||||||
|
Site,
|
||||||
UserUserGroup,
|
UserUserGroup,
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -1875,6 +1876,20 @@ class Resource(models.Model, AuthorMixin):
|
|||||||
help_text="Author of the resource",
|
help_text="Author of the resource",
|
||||||
related_name="resources",
|
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:
|
def __str__(self) -> str:
|
||||||
return self.name
|
return self.name
|
||||||
@@ -1902,7 +1917,18 @@ class Resource(models.Model, AuthorMixin):
|
|||||||
else:
|
else:
|
||||||
html = self.name
|
html = self.name
|
||||||
|
|
||||||
return format_html("<details class='resource-block'><summary>{}</summary>{}</details>", 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(
|
||||||
|
"<details class='resource-block'><summary>{}</summary><div>{}</div><div class='text-muted small'>{}</div></details>",
|
||||||
|
self.name,
|
||||||
|
mark_safe(html),
|
||||||
|
meta,
|
||||||
|
)
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user