From cbed5fe5fba48687f3e085c16f17761f5b0ee878 Mon Sep 17 00:00:00 2001
From: Dylan Hillerbrand
Date: Mon, 29 Jul 2024 14:48:40 -0400
Subject: [PATCH 1/3] feat(source model): add temporary segment field to source
Adds the segment_m2m many-to-many field to the source model.
This additional field ensures that the data currently in the
segment field is not overwritten. Once data in the segment
field is transferred, this field can be renamed.
Changes to the source create and source edit forms make this
new field editable.
Refs: #1549
---
django/cantusdb_project/main_app/forms.py | 5 ++++
.../migrations/0026_source_segment_m2m.py | 23 +++++++++++++++++++
.../main_app/models/source.py | 3 +++
.../main_app/templates/source_create.html | 6 +++++
.../main_app/templates/source_edit.html | 6 +++++
5 files changed, 43 insertions(+)
create mode 100644 django/cantusdb_project/main_app/migrations/0026_source_segment_m2m.py
diff --git a/django/cantusdb_project/main_app/forms.py b/django/cantusdb_project/main_app/forms.py
index dceae1750..c2469b672 100644
--- a/django/cantusdb_project/main_app/forms.py
+++ b/django/cantusdb_project/main_app/forms.py
@@ -26,6 +26,7 @@
from django.contrib.admin.widgets import (
FilteredSelectMultiple,
)
+from django.forms.widgets import CheckboxSelectMultiple
from dal import autocomplete
# ModelForm allows to build a form directly from a model
@@ -176,6 +177,7 @@ class Meta:
# "siglum",
"holding_institution",
"shelfmark",
+ "segment_m2m",
"provenance",
"provenance_notes",
"full_source",
@@ -204,6 +206,7 @@ class Meta:
url="holding-autocomplete"
),
"shelfmark": TextInputWidget(),
+ "segment_m2m": CheckboxSelectMultiple(),
"provenance": autocomplete.ModelSelect2(url="provenance-autocomplete"),
"provenance_notes": TextInputWidget(),
"date": TextInputWidget(),
@@ -365,6 +368,7 @@ class Meta:
# "siglum",
"holding_institution",
"shelfmark",
+ "segment_m2m",
"provenance",
"provenance_notes",
"full_source",
@@ -392,6 +396,7 @@ class Meta:
url="holding-autocomplete"
),
"shelfmark": TextInputWidget(),
+ "segment_m2m": CheckboxSelectMultiple(),
"provenance": autocomplete.ModelSelect2(url="provenance-autocomplete"),
"provenance_notes": TextInputWidget(),
"date": TextInputWidget(),
diff --git a/django/cantusdb_project/main_app/migrations/0026_source_segment_m2m.py b/django/cantusdb_project/main_app/migrations/0026_source_segment_m2m.py
new file mode 100644
index 000000000..c3911e6e3
--- /dev/null
+++ b/django/cantusdb_project/main_app/migrations/0026_source_segment_m2m.py
@@ -0,0 +1,23 @@
+# Generated by Django 4.2.11 on 2024-07-26 17:03
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ("main_app", "0025_alter_source_date"),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name="source",
+ name="segment_m2m",
+ field=models.ManyToManyField(
+ blank=True,
+ related_name="sources",
+ to="main_app.segment",
+ verbose_name="Segments",
+ ),
+ ),
+ ]
diff --git a/django/cantusdb_project/main_app/models/source.py b/django/cantusdb_project/main_app/models/source.py
index e6a1aad7c..988942128 100644
--- a/django/cantusdb_project/main_app/models/source.py
+++ b/django/cantusdb_project/main_app/models/source.py
@@ -105,6 +105,9 @@ class Source(BaseModel):
segment = models.ForeignKey(
"Segment", on_delete=models.PROTECT, blank=True, null=True
)
+ segment_m2m = models.ManyToManyField(
+ "Segment", blank=True, related_name="sources", verbose_name="Segments"
+ )
source_status = models.CharField(
blank=True, null=True, choices=source_status_choices, max_length=255
)
diff --git a/django/cantusdb_project/main_app/templates/source_create.html b/django/cantusdb_project/main_app/templates/source_create.html
index b196677bc..541ef7eab 100644
--- a/django/cantusdb_project/main_app/templates/source_create.html
+++ b/django/cantusdb_project/main_app/templates/source_create.html
@@ -64,6 +64,12 @@ Create Source
{{ form.shelfmark.help_text }}
+
+
+
{{ form.segment_m2m }}
+