From d618c1c14a71ce06da6a626bdb208ed7cf71365a Mon Sep 17 00:00:00 2001 From: mipel Date: Fri, 23 Jul 2021 09:36:43 +0200 Subject: [PATCH] Intervention relations enhancements * refactors model relation to compensation and payment by applying 1-n instead of n-n --- compensation/models.py | 16 ++++++++++++++++ intervention/models.py | 5 ++--- 2 files changed, 18 insertions(+), 3 deletions(-) diff --git a/compensation/models.py b/compensation/models.py index 9b84ddea..28d34edc 100644 --- a/compensation/models.py +++ b/compensation/models.py @@ -12,6 +12,7 @@ from django.utils import timezone from django.utils.timezone import now from compensation.settings import COMPENSATION_IDENTIFIER_LENGTH, COMPENSATION_IDENTIFIER_TEMPLATE +from intervention.models import Intervention from konova.models import BaseObject, BaseResource, Geometry from konova.utils.generators import generate_random_string from organisation.models import Organisation @@ -29,6 +30,13 @@ class Payment(BaseResource): blank=True, help_text="Refers to german money transfer 'Verwendungszweck'", ) + intervention = models.ForeignKey( + Intervention, + null=True, + blank=True, + on_delete=models.CASCADE, + related_name='payments' + ) class CompensationControl(BaseResource): @@ -81,6 +89,14 @@ class Compensation(BaseObject): geometry = models.ForeignKey(Geometry, null=True, blank=True, on_delete=models.SET_NULL) documents = models.ManyToManyField("konova.Document", blank=True) + intervention = models.ForeignKey( + Intervention, + on_delete=models.CASCADE, + null=True, + blank=True, + related_name='compensations' + ) + # Users having access on this object users = models.ManyToManyField(User) diff --git a/intervention/models.py b/intervention/models.py index cbc41c3f..d5430c7b 100644 --- a/intervention/models.py +++ b/intervention/models.py @@ -11,7 +11,6 @@ from django.db import transaction from django.utils import timezone from django.utils.timezone import now -from compensation.models import Payment, Compensation from intervention.settings import INTERVENTION_IDENTIFIER_LENGTH, INTERVENTION_IDENTIFIER_TEMPLATE from konova.models import BaseObject, Geometry from konova.utils.generators import generate_random_string @@ -51,8 +50,8 @@ class Intervention(BaseObject): next_version = models.ForeignKey("Intervention", null=True, blank=True, on_delete=models.DO_NOTHING) # Compensation or payments, one-directional - payments = models.ManyToManyField(Payment, related_name="+", blank=True) - compensations = models.ManyToManyField(Compensation, related_name="+", blank=True) + #payments = models.ManyToManyField(Payment, related_name="+", blank=True) + #compensations = models.ManyToManyField(Compensation, related_name="+", blank=True) # Users having access on this object users = models.ManyToManyField(User)