1
Fork 0
mirror of https://github.com/Steffo99/sophon.git synced 2024-12-23 07:14:21 +00:00

Add RelatedToProject abstract base class to find the project instance of any model

This commit is contained in:
Steffo 2021-04-12 17:42:06 +02:00 committed by Stefano Pigozzi
parent 5ffe48e4e0
commit 8c8833d989

View file

@ -6,6 +6,20 @@ import pandasdmx
import pandasdmx.message import pandasdmx.message
import typing as t import typing as t
import json 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): class DataSource(models.Model):
@ -298,12 +312,15 @@ class DataFlow(models.Model):
return f"[{self.datasource}] {self.id}" 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 A research :class:`.Project` is a work which may use zero or more :class:`.DataSource`\\ s to prove or disprove an
hypothesis. hypothesis.
""" """
def get_project(self):
return self
slug = models.SlugField( slug = models.SlugField(
"Slug", "Slug",
help_text="Unique alphanumeric string which identifies the project.", help_text="Unique alphanumeric string which identifies the project.",