From 0b6661c018cefdd3ed966be7e8e0d2437ebcd4db Mon Sep 17 00:00:00 2001 From: Ross Date: Mon, 16 Feb 2026 13:32:06 +0000 Subject: [PATCH] Refactor NormalCase model: remove 'added_by' field, add 'author' ManyToManyField; update related views and templates for editing functionality --- atlas/admin.py | 2 +- .../0091_remove_normalcase_added_by.py | 17 ++++++ atlas/migrations/0092_normalcase_author.py | 20 +++++++ atlas/models.py | 17 +++--- atlas/templates/atlas/normals_list.html | 16 +++++- .../atlas/partials/_normal_form.html | 4 +- .../atlas/partials/_normal_toggle.html | 30 +++++++---- atlas/urls.py | 1 + atlas/views.py | 52 ++++++++++++++++++- 9 files changed, 134 insertions(+), 25 deletions(-) create mode 100644 atlas/migrations/0091_remove_normalcase_added_by.py create mode 100644 atlas/migrations/0092_normalcase_author.py diff --git a/atlas/admin.py b/atlas/admin.py index 97908782..155938a0 100755 --- a/atlas/admin.py +++ b/atlas/admin.py @@ -82,7 +82,7 @@ admin.site.register(CaseCollection, CaseCollectionAdmin) class NormalCaseAdmin(VersionAdmin): - list_display = ("case", "display_age", "examination", "modality", "added_by", "added_date") + list_display = ("case", "display_age", "examination", "modality", "added_date") list_filter = ("examination", "modality") search_fields = ("case__title", "case__pk") diff --git a/atlas/migrations/0091_remove_normalcase_added_by.py b/atlas/migrations/0091_remove_normalcase_added_by.py new file mode 100644 index 00000000..b8fbcc31 --- /dev/null +++ b/atlas/migrations/0091_remove_normalcase_added_by.py @@ -0,0 +1,17 @@ +# Generated by Django 6.0.1 on 2026-02-16 13:28 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('atlas', '0090_casecollection_created_casecollection_updated'), + ] + + operations = [ + migrations.RemoveField( + model_name='normalcase', + name='added_by', + ), + ] diff --git a/atlas/migrations/0092_normalcase_author.py b/atlas/migrations/0092_normalcase_author.py new file mode 100644 index 00000000..e4968256 --- /dev/null +++ b/atlas/migrations/0092_normalcase_author.py @@ -0,0 +1,20 @@ +# Generated by Django 6.0.1 on 2026-02-16 13:29 + +from django.conf import settings +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('atlas', '0091_remove_normalcase_added_by'), + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ] + + operations = [ + migrations.AddField( + model_name='normalcase', + name='author', + field=models.ManyToManyField(blank=True, related_name='normal_cases', to=settings.AUTH_USER_MODEL), + ), + ] diff --git a/atlas/models.py b/atlas/models.py index 7949a338..e5e129ab 100644 --- a/atlas/models.py +++ b/atlas/models.py @@ -766,7 +766,7 @@ class Case(models.Model, AuthorMixin, QuestionMixin): return json.dumps(results) -class NormalCase(models.Model): +class NormalCase(models.Model, AuthorMixin): """Marks a Case as a 'normal' example used in the Atlas normals section. This version stores a canonical `age_days` integer (patient age in days). @@ -819,16 +819,15 @@ class NormalCase(models.Model): help_text="Primary modality for this normal case (optional).", ) - added_by = models.ForeignKey( - settings.AUTH_USER_MODEL, - null=True, - blank=True, - on_delete=models.SET_NULL, - related_name="added_normals", - ) - added_date = models.DateTimeField(default=timezone.now) + + author = models.ManyToManyField( + settings.AUTH_USER_MODEL, + blank=True, + related_name="normal_cases", + ) + notes = models.TextField(null=True, blank=True) class Meta: diff --git a/atlas/templates/atlas/normals_list.html b/atlas/templates/atlas/normals_list.html index a7bd7381..ab2b94d2 100644 --- a/atlas/templates/atlas/normals_list.html +++ b/atlas/templates/atlas/normals_list.html @@ -30,7 +30,8 @@ {% if page_obj.object_list %}
{% for normal in page_obj.object_list %} - +
+
{{ normal.case.title }}
{{ normal.added_date|date:"Y-m-d" }} @@ -43,7 +44,18 @@ {% if normal.notes %}

{{ normal.notes }}

{% endif %} -
+ +
+ {% if request.user.is_superuser or request.user in normal.author.all %} + + {% endif %} +
+
{% endfor %}
{% else %} diff --git a/atlas/templates/atlas/partials/_normal_form.html b/atlas/templates/atlas/partials/_normal_form.html index 4b8757de..80f35a7d 100644 --- a/atlas/templates/atlas/partials/_normal_form.html +++ b/atlas/templates/atlas/partials/_normal_form.html @@ -1,10 +1,10 @@