From c87908dfae4041ad40f7262d56379866669bb154 Mon Sep 17 00:00:00 2001 From: Oliver Sauder Date: Thu, 13 Dec 2018 14:31:49 +0100 Subject: [PATCH] Let a document only be assigned to one case A case enforces a workflow so it doesn't make sense to edit the same document in two different workflows. --- caluma/form/schema.py | 1 - caluma/tests/snapshots/snap_test_schema.py | 1 + .../migrations/0002_auto_20181213_1334.py | 25 +++++++++++++++++++ caluma/workflow/models.py | 6 ++--- 4 files changed, 29 insertions(+), 4 deletions(-) create mode 100644 caluma/workflow/migrations/0002_auto_20181213_1334.py diff --git a/caluma/form/schema.py b/caluma/form/schema.py index 02393f25e..7c1055bfb 100644 --- a/caluma/form/schema.py +++ b/caluma/form/schema.py @@ -346,7 +346,6 @@ class Document(DjangoObjectType): class Meta: model = models.Document interfaces = (graphene.Node,) - exclude_fields = ("cases",) filter_fields = ("form",) diff --git a/caluma/tests/snapshots/snap_test_schema.py b/caluma/tests/snapshots/snap_test_schema.py index 3991afe9e..e736cdb2f 100644 --- a/caluma/tests/snapshots/snap_test_schema.py +++ b/caluma/tests/snapshots/snap_test_schema.py @@ -198,6 +198,7 @@ form: Form! meta: JSONString! answers(before: String, after: String, first: Int, last: Int, question: ID, search: String, orderBy: [AnswerOrdering]): AnswerConnection + case: Case } type DocumentConnection { diff --git a/caluma/workflow/migrations/0002_auto_20181213_1334.py b/caluma/workflow/migrations/0002_auto_20181213_1334.py new file mode 100644 index 000000000..22f47c76d --- /dev/null +++ b/caluma/workflow/migrations/0002_auto_20181213_1334.py @@ -0,0 +1,25 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.11.17 on 2018-12-13 13:34 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [("workflow", "0001_initial")] + + operations = [ + migrations.AlterField( + model_name="case", + name="document", + field=models.OneToOneField( + blank=True, + null=True, + on_delete=django.db.models.deletion.PROTECT, + related_name="case", + to="form.Document", + ), + ) + ] diff --git a/caluma/workflow/models.py b/caluma/workflow/models.py index 28d4c228c..a5295b2c6 100644 --- a/caluma/workflow/models.py +++ b/caluma/workflow/models.py @@ -66,10 +66,10 @@ class Case(UUIDModel): ) status = models.CharField(choices=STATUS_CHOICE_TUPLE, max_length=50, db_index=True) meta = JSONField(default={}) - document = models.ForeignKey( + document = models.OneToOneField( "form.Document", - on_delete=models.DO_NOTHING, - related_name="cases", + on_delete=models.PROTECT, + related_name="case", blank=True, null=True, )