diff --git a/consultation_analyser/consultations/migrations/0002_alter_theme_options_theme_question_and_more.py b/consultation_analyser/consultations/migrations/0002_alter_theme_options_theme_question_and_more.py new file mode 100644 index 000000000..defd03b8f --- /dev/null +++ b/consultation_analyser/consultations/migrations/0002_alter_theme_options_theme_question_and_more.py @@ -0,0 +1,30 @@ +# Generated by Django 5.0.3 on 2024-03-26 21:27 + +import django.db.models.deletion +from django.db import migrations, models + + +class Migration(migrations.Migration): + dependencies = [ + ("consultations", "0001_initial"), + ] + + operations = [ + migrations.AlterModelOptions( + name="theme", + options={}, + ), + migrations.AddField( + model_name="theme", + name="question", + field=models.ForeignKey( + null=True, on_delete=django.db.models.deletion.CASCADE, to="consultations.question" + ), + ), + migrations.AddConstraint( + model_name="theme", + constraint=models.UniqueConstraint( + fields=("summary", "label", "keywords", "question"), name="unique_up_to_question" + ), + ), + ] diff --git a/consultation_analyser/consultations/models.py b/consultation_analyser/consultations/models.py index a841308e3..10cf31110 100644 --- a/consultation_analyser/consultations/models.py +++ b/consultation_analyser/consultations/models.py @@ -61,6 +61,12 @@ class Theme(UUIDPrimaryKeyModel, TimeStampedModel): label = models.CharField(max_length=256, blank=True) summary = models.TextField(blank=True) keywords = models.JSONField(default=list) + question = models.ForeignKey(Question, on_delete=models.CASCADE, null=True) + + class Meta: + constraints = [ + models.UniqueConstraint(fields=["summary", "label", "keywords", "question"], name="unique_up_to_question"), + ] class Answer(UUIDPrimaryKeyModel, TimeStampedModel): diff --git a/docs/erd.png b/docs/erd.png index 51b60ed8a..1703189a2 100644 Binary files a/docs/erd.png and b/docs/erd.png differ