From ecb26c3908262f5de85bc7581cf9de431c4bfa25 Mon Sep 17 00:00:00 2001 From: Ivan <8611739+IRBorisov@users.noreply.github.com> Date: Thu, 25 Jul 2024 21:18:44 +0300 Subject: [PATCH] Add inheritance model --- .../apps/oss/migrations/0002_inheritance.py | 28 +++++++++++++++++++ .../backend/apps/oss/models/Inheritance.py | 8 ++---- rsconcept/backend/apps/oss/models/__init__.py | 1 + 3 files changed, 31 insertions(+), 6 deletions(-) create mode 100644 rsconcept/backend/apps/oss/migrations/0002_inheritance.py diff --git a/rsconcept/backend/apps/oss/migrations/0002_inheritance.py b/rsconcept/backend/apps/oss/migrations/0002_inheritance.py new file mode 100644 index 00000000..b3463bbe --- /dev/null +++ b/rsconcept/backend/apps/oss/migrations/0002_inheritance.py @@ -0,0 +1,28 @@ +# Generated by Django 5.0.7 on 2024-07-25 18:08 + +import django.db.models.deletion +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('oss', '0001_initial'), + ('rsform', '0001_initial'), + ] + + operations = [ + migrations.CreateModel( + name='Inheritance', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('child', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='as_child', to='rsform.constituenta', verbose_name='Наследованная конституента')), + ('parent', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='as_parent', to='rsform.constituenta', verbose_name='Исходная конституента')), + ], + options={ + 'verbose_name': 'Наследование синтеза', + 'verbose_name_plural': 'Отношение наследования конституент', + 'unique_together': {('parent', 'child')}, + }, + ), + ] diff --git a/rsconcept/backend/apps/oss/models/Inheritance.py b/rsconcept/backend/apps/oss/models/Inheritance.py index 1292acbd..4ebd9826 100644 --- a/rsconcept/backend/apps/oss/models/Inheritance.py +++ b/rsconcept/backend/apps/oss/models/Inheritance.py @@ -4,12 +4,6 @@ from django.db.models import CASCADE, ForeignKey, Model class Inheritance(Model): ''' Inheritance links parent and child constituents in synthesis operation.''' - operation: ForeignKey = ForeignKey( - verbose_name='Операция', - to='oss.Operation', - on_delete=CASCADE - ) - parent: ForeignKey = ForeignKey( verbose_name='Исходная конституента', to='rsform.Constituenta', @@ -27,6 +21,8 @@ class Inheritance(Model): ''' Model metadata. ''' verbose_name = 'Наследование синтеза' verbose_name_plural = 'Отношение наследования конституент' + unique_together = [['parent', 'child']] + def __str__(self) -> str: return f'{self.parent} -> {self.child}' diff --git a/rsconcept/backend/apps/oss/models/__init__.py b/rsconcept/backend/apps/oss/models/__init__.py index cb389382..562bc9da 100644 --- a/rsconcept/backend/apps/oss/models/__init__.py +++ b/rsconcept/backend/apps/oss/models/__init__.py @@ -1,6 +1,7 @@ ''' Django: Models. ''' from .Argument import Argument +from .Inheritance import Inheritance from .Operation import Operation, OperationType from .OperationSchema import OperationSchema from .Substitution import Substitution