mirror of
https://github.com/Steffo99/sophon.git
synced 2024-12-22 23:04:21 +00:00
✨ Add RelatedToProject abstract base class to find the project instance of any model
This commit is contained in:
parent
5ffe48e4e0
commit
8c8833d989
1 changed files with 18 additions and 1 deletions
|
@ -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.",
|
||||
|
|
Loading…
Reference in a new issue