Skip to content

Rework relationship between ObjectComponent and CodeRun #173

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from
Draft
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
18 changes: 10 additions & 8 deletions data_management/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

from django.core.exceptions import ValidationError
from django.db import models
from django.db.models.deletion import PROTECT
from django.urls import reverse
from dynamic_validator import ModelFieldRequiredMixin
from django.contrib.auth import get_user_model
Expand Down Expand Up @@ -334,25 +335,27 @@ class ObjectComponent(BaseModel):

`whole_object` (*optional*): Specifies if this `ObjectComponent` refers to the whole object or not (by default this is `False`)

`output_of`: `CodeRun` that the `ObjectComponent` was created as an output of

### Read-only Fields:
`url`: Reference to the instance of the `ObjectComponent`, final integer is the `ObjectComponent` id

`last_updated`: Datetime that this record was last updated

`updated_by`: Reference to the user that updated this record

`input_of`: List of `CodeRun` that the `ObjectComponent` is being used as an input to
`input_to`: List of `CodeRun` that the `ObjectComponent` was used as an input to

`output_of`: List of `CodeRun` that the `ObjectComponent` was created as an output of
"""
ADMIN_LIST_FIELDS = ('object', 'name')
EXTRA_DISPLAY_FIELDS = ('inputs_of', 'outputs_of')
EXTRA_DISPLAY_FIELDS = ('input_to')

object = models.ForeignKey(Object, on_delete=models.PROTECT, related_name='components', null=False)
name = NameField(null=False, blank=False)
issues = models.ManyToManyField(Issue, related_name='component_issues', blank=True)
description = models.TextField(max_length=TEXT_FIELD_LENGTH, null=True, blank=True)
whole_object = models.BooleanField(default=False)
output_of = models.ForeignKey("CodeRun", on_delete=PROTECT, blank=True, related_name="outputs")

class Meta:
constraints = [
Expand Down Expand Up @@ -382,8 +385,6 @@ class CodeRun(BaseModel):

`inputs`: List of `ObjectComponent` that the `CodeRun` used as inputs

`outputs`: List of `ObjectComponent` that the `CodeRun` produced as outputs

`uuid` (*optional*): UUID of the `CodeRun`. If not specified a UUID is generated automatically.

### Read-only Fields:
Expand All @@ -392,19 +393,20 @@ class CodeRun(BaseModel):
`last_updated`: Datetime that this record was last updated

`updated_by`: Reference to the user that updated this record

`outputs`: List of `ObjectComponent` that the `CodeRun` produced as outputs
"""
ADMIN_LIST_FIELDS = ('description',)
EXTRA_DISPLAY_FIELDS = ("outputs")

code_repo = models.ForeignKey(Object, on_delete=models.PROTECT, related_name='code_repo_of', null=True, blank=True)
model_config = models.ForeignKey(Object, on_delete=models.PROTECT, related_name='config_of', null=True, blank=True)
submission_script = models.ForeignKey(Object, on_delete=models.PROTECT, related_name='submission_script_of', null=False, blank=False)
run_date = models.DateTimeField(null=False, blank=False)
description = models.CharField(max_length=CHAR_FIELD_LENGTH, null=False, blank=False)
inputs = models.ManyToManyField(ObjectComponent, related_name='inputs_of', blank=True)
outputs = models.ManyToManyField(ObjectComponent, related_name='outputs_of', blank=True)
inputs = models.ManyToManyField(ObjectComponent, related_name='input_to', blank=True)
uuid = models.UUIDField(default=uuid4, editable=True, unique=True)


def __str__(self):
if self.code_repo:
return '%s run %s' % (self.code_repo, self.description)
Expand Down