From 8c8833d98990faa62f5b78c59dbd228e1565534e Mon Sep 17 00:00:00 2001 From: Stefano Pigozzi Date: Mon, 12 Apr 2021 17:42:06 +0200 Subject: [PATCH] =?UTF-8?q?=E2=9C=A8=20Add=20RelatedToProject=20abstract?= =?UTF-8?q?=20base=20class=20to=20find=20the=20project=20instance=20of=20a?= =?UTF-8?q?ny=20model?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sophon/core/models.py | 19 ++++++++++++++++++- 1 file changed, 18 insertions(+), 1 deletion(-) diff --git a/sophon/core/models.py b/sophon/core/models.py index 6fd4f84..32ba696 100644 --- a/sophon/core/models.py +++ b/sophon/core/models.py @@ -6,6 +6,20 @@ import pandasdmx import pandasdmx.message import typing as t import json +import abc + + +class RelatedToProject(metaclass=abc.ABCMeta): + """ + A model which is related to :class:`.Project` in some way. + """ + + @abc.abstractmethod + def get_project(self) -> "Project": + """ + :return: The project this object is related to. + """ + raise NotImplementedError() class DataSource(models.Model): @@ -298,12 +312,15 @@ class DataFlow(models.Model): return f"[{self.datasource}] {self.id}" -class Project(models.Model): +class Project(models.Model, RelatedToProject): """ A research :class:`.Project` is a work which may use zero or more :class:`.DataSource`\\ s to prove or disprove an hypothesis. """ + def get_project(self): + return self + slug = models.SlugField( "Slug", help_text="Unique alphanumeric string which identifies the project.",