ConceptPortal-public/rsconcept/backend/apps/oss/models/Operation.py
2025-04-06 15:49:43 +03:00

85 lines
2.0 KiB
Python
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

''' Models: Operation in OSS. '''
# pylint: disable=duplicate-code
from django.db.models import (
CASCADE,
SET_NULL,
CharField,
ForeignKey,
Model,
QuerySet,
TextChoices,
TextField
)
from .Argument import Argument
from .Substitution import Substitution
class OperationType(TextChoices):
''' Type of operation. '''
INPUT = 'input'
SYNTHESIS = 'synthesis'
class Operation(Model):
''' Operational schema Unit.'''
oss = ForeignKey(
verbose_name='Схема синтеза',
to='library.LibraryItem',
on_delete=CASCADE,
related_name='operations'
)
operation_type = CharField(
verbose_name='Тип',
max_length=10,
choices=OperationType.choices,
default=OperationType.INPUT
)
result = ForeignKey(
verbose_name='Связанная КС',
to='library.LibraryItem',
blank=True,
null=True,
on_delete=SET_NULL,
related_name='producer'
)
parent = ForeignKey(
verbose_name='Содержащий блок',
to='oss.Block',
blank=True,
null=True,
on_delete=SET_NULL,
related_name='as_child_operation'
)
alias = CharField(
verbose_name='Шифр',
max_length=255,
blank=True
)
title = TextField(
verbose_name='Название',
blank=True
)
description = TextField(
verbose_name='Описание',
blank=True
)
class Meta:
''' Model metadata. '''
verbose_name = 'Операция'
verbose_name_plural = 'Операции'
def __str__(self) -> str:
return f'Операция {self.alias}'
def getQ_arguments(self) -> QuerySet[Argument]:
''' Operation arguments. '''
return Argument.objects.filter(operation=self)
def getQ_substitutions(self) -> QuerySet[Substitution]:
''' Operation substitutions. '''
return Substitution.objects.filter(operation=self)