Skip to content

Commit

Permalink
🎨 Iterate
Browse files Browse the repository at this point in the history
Signed-off-by: zethson <[email protected]>
  • Loading branch information
Zethson committed Nov 21, 2024
1 parent 0bced45 commit d0df0a9
Show file tree
Hide file tree
Showing 2 changed files with 54 additions and 27 deletions.
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
# Generated by Django 5.1.3 on 2024-11-20 12:42
# Generated by Django 5.1.3 on 2024-11-21 14:00

import django.core.validators
import django.db.models.deletion
Expand All @@ -12,10 +12,30 @@
class Migration(migrations.Migration):
dependencies = [
("lnschema_core", "0069_squashed"),
("ourprojects", "0002_alter_artifactproject_artifact_and_more"),
("ourprojects", "0001_initial"),
]

operations = [
migrations.AlterField(
model_name="artifactproject",
name="artifact",
field=lnschema_core.fields.ForeignKey(
blank=True,
on_delete=django.db.models.deletion.CASCADE,
related_name="links_project",
to="lnschema_core.artifact",
),
),
migrations.AlterField(
model_name="artifactproject",
name="project",
field=lnschema_core.fields.ForeignKey(
blank=True,
on_delete=django.db.models.deletion.PROTECT,
related_name="links_artifact",
to="ourprojects.project",
),
),
migrations.CreateModel(
name="ArtifactReference",
fields=[
Expand Down Expand Up @@ -122,9 +142,7 @@ class Migration(migrations.Migration):
),
(
"internal",
lnschema_core.fields.BooleanField(
blank=True, default=False, null=True
),
lnschema_core.fields.BooleanField(blank=True, default=False),
),
(
"_previous_runs",
Expand Down Expand Up @@ -231,9 +249,7 @@ class Migration(migrations.Migration):
),
(
"preprint",
lnschema_core.fields.BooleanField(
blank=True, default=None, null=True
),
lnschema_core.fields.BooleanField(blank=True, default=False),
),
(
"journal",
Expand All @@ -249,9 +265,7 @@ class Migration(migrations.Migration):
),
(
"published_at",
lnschema_core.fields.DateTimeField(
blank=True, default=None, null=True
),
lnschema_core.fields.DateField(blank=True, default=None, null=True),
),
(
"_previous_runs",
Expand Down
45 changes: 29 additions & 16 deletions ourprojects/models.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
from __future__ import annotations

from datetime import datetime # noqa
from datetime import date # noqa

from django.core.validators import RegexValidator
from django.db import models
Expand All @@ -10,7 +10,7 @@
BigIntegerField,
BooleanField,
CharField,
DateTimeField,
DateField,
EmailField,
ForeignKey,
TextField,
Expand All @@ -33,8 +33,9 @@ class Person(Record, CanCurate, TracksRun, TracksUpdates, ValidateFields):
Example:
>>> person = Person(
... name="A paper title",
... internal=False,
... name="Jane Doe",
... email="[email protected]",
... internal=True,
... ).save()
"""

Expand All @@ -43,22 +44,24 @@ class Meta(Record.Meta, TracksRun.Meta, TracksUpdates.Meta):

id: int = models.AutoField(primary_key=True)
"""Internal id, valid only in one DB instance."""
uid: str = CharField(max_length=12, unique=True, default=ids.base62_12)
uid: str = CharField(unique=True, max_length=12, default=ids.base62_12)
"""Universal id, valid across DB instances."""
name: str = CharField(db_index=True)
"""Name of the person (forename(s) lastname)."""
email: str = EmailField(null=True, default=None)
email: str | None = EmailField(null=True, default=None)
"""Email of the person."""
internal: bool = BooleanField(null=True, default=False)
internal: bool = BooleanField(default=False)
"""Whether the person is internal to the organization or not."""


class Project(Record, CanCurate, TracksRun, TracksUpdates, ValidateFields):
"""Projects with associated persons and references.
Example:
>>> Project = Project(
... name="My project name",
>>> project = Project(
... name="My Project Name",
... abbr="MPN",
... url="https://example.com/my_project",
... ).save()
"""

Expand All @@ -76,6 +79,7 @@ class Meta(Record.Meta, TracksRun.Meta, TracksUpdates.Meta):
url: str | None = URLField(max_length=255, null=True, default=None)
"""A URL to view."""
persons: Person = models.ManyToManyField(Person, related_name="project_persons")
"""Persons associated with this project."""
references: Reference = models.ManyToManyField(
"Reference", related_name="project_references"
)
Expand All @@ -91,8 +95,16 @@ class Reference(Record, CanCurate, TracksRun, TracksUpdates, ValidateFields):
Example:
>>> reference = Reference(
... name="A paper title",
... doi="A doi",
... name="A Paper Title",
... abbr="APT",
... url="https://doi.org/10.1000/xyz123",
... pubmed_id=12345678,
... doi="10.1000/xyz123",
... preprint=False,
... journal="Nature Biotechnology",
... description="A groundbreaking research paper.",
... text="A really informative abstract.",
... published_at=date(2023, 11, 21),
... ).save()
"""

Expand All @@ -101,7 +113,8 @@ class Meta(Record.Meta, TracksRun.Meta, TracksUpdates.Meta):

id: int = models.AutoField(primary_key=True)
"""Internal id, valid only in one DB instance."""
uid: str = CharField(max_length=12, unique=True, default=ids.base62_12)
uid: str = CharField(unique=True, max_length=12, default=ids.base62_12)
"""Universal id, valid across DB instances."""
"""Universal id, valid across DB instances."""
name: str = CharField(db_index=True)
"""Title or name of the reference document."""
Expand All @@ -127,15 +140,15 @@ class Meta(Record.Meta, TracksRun.Meta, TracksUpdates.Meta):
],
)
"""Digital Object Identifier (DOI) for the reference."""
preprint: bool = BooleanField(null=True, default=None)
preprint: bool = BooleanField(default=False)
"""Whether the reference is from a preprint."""
journal: str = TextField(null=True)
journal: str | None = TextField(null=True)
"""Name of the journal."""
description: str = TextField(null=True)
description: str | None = TextField(null=True)
"""Description of the reference."""
text: str | None = TextField(null=True)
"""Abstract or full text of the reference."""
published_at: datetime = DateTimeField(null=True, default=None)
published_at: date = DateField(null=True, default=None)
"""Publication date."""
persons: Person = models.ManyToManyField(Person, related_name="reference_persons")
artifacts: Artifact = models.ManyToManyField(
Expand Down

0 comments on commit d0df0a9

Please sign in to comment.