Skip to content

Commit

Permalink
✨ Add Person and Reference models (#5)
Browse files Browse the repository at this point in the history
Signed-off-by: zethson <lukas.heumos@posteo.net>
  • Loading branch information
Zethson authored Nov 21, 2024
1 parent 3ce7d1e commit 37cad62
Show file tree
Hide file tree
Showing 4 changed files with 463 additions and 13 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -108,3 +108,5 @@ docs/conf.py
_docs_tmp*
docs/test-ourprojects/
test-ourprojects/
test.ipynb
run-tests
4 changes: 3 additions & 1 deletion ourprojects/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,9 @@
.. autosummary::
:toctree: .
Person
Project
Reference
"""

__version__ = "0.0.1" # denote a pre-release for 0.1.0 with 0.1rc1
Expand All @@ -32,4 +34,4 @@ def __getattr__(name):
import lamindb

del __getattr__ # delete so that imports work out
from .models import Project
from .models import Person, Project, Reference
319 changes: 315 additions & 4 deletions ourprojects/migrations/0001_initial.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
# Generated by Django 5.2 on 2024-11-21 10:57
# Generated by Django 5.1.3 on 2024-11-21 16:47

import django.core.validators
import django.db.models.deletion
import lnschema_core.fields
import lnschema_core.ids
Expand Down Expand Up @@ -42,7 +43,6 @@ class Migration(migrations.Migration):
"artifact",
lnschema_core.fields.ForeignKey(
blank=True,
default=None,
on_delete=django.db.models.deletion.CASCADE,
related_name="links_project",
to="lnschema_core.artifact",
Expand Down Expand Up @@ -83,6 +83,149 @@ class Migration(migrations.Migration):
],
bases=(lnschema_core.models.LinkORM, models.Model),
),
migrations.CreateModel(
name="ArtifactReference",
fields=[
(
"created_at",
lnschema_core.fields.DateTimeField(
auto_now_add=True, db_index=True
),
),
("id", models.BigAutoField(primary_key=True, serialize=False)),
(
"label_ref_is_name",
lnschema_core.fields.BooleanField(
blank=True, default=None, null=True
),
),
(
"feature_ref_is_name",
lnschema_core.fields.BooleanField(
blank=True, default=None, null=True
),
),
(
"artifact",
lnschema_core.fields.ForeignKey(
blank=True,
on_delete=django.db.models.deletion.CASCADE,
related_name="links_reference",
to="lnschema_core.artifact",
),
),
(
"created_by",
lnschema_core.fields.ForeignKey(
blank=True,
default=lnschema_core.users.current_user_id,
on_delete=django.db.models.deletion.PROTECT,
related_name="+",
to="lnschema_core.user",
),
),
(
"feature",
lnschema_core.fields.ForeignKey(
blank=True,
default=None,
null=True,
on_delete=django.db.models.deletion.PROTECT,
related_name="links_artifactreference",
to="lnschema_core.feature",
),
),
(
"run",
lnschema_core.fields.ForeignKey(
blank=True,
default=lnschema_core.models.current_run,
null=True,
on_delete=django.db.models.deletion.PROTECT,
related_name="+",
to="lnschema_core.run",
),
),
],
bases=(lnschema_core.models.LinkORM, models.Model),
),
migrations.CreateModel(
name="Person",
fields=[
(
"created_at",
lnschema_core.fields.DateTimeField(
auto_now_add=True, db_index=True
),
),
(
"updated_at",
lnschema_core.fields.DateTimeField(auto_now=True, db_index=True),
),
("id", models.AutoField(primary_key=True, serialize=False)),
(
"uid",
lnschema_core.fields.CharField(
blank=True,
db_index=True,
default=lnschema_core.ids.base62_8,
max_length=8,
unique=True,
),
),
(
"name",
lnschema_core.fields.CharField(
blank=True, db_index=True, default=None, max_length=255
),
),
(
"email",
lnschema_core.fields.EmailField(
blank=True, default=None, max_length=254, null=True
),
),
(
"external",
lnschema_core.fields.BooleanField(
blank=True, db_index=True, default=True
),
),
(
"_previous_runs",
models.ManyToManyField(related_name="+", to="lnschema_core.run"),
),
(
"created_by",
lnschema_core.fields.ForeignKey(
blank=True,
default=lnschema_core.users.current_user_id,
on_delete=django.db.models.deletion.PROTECT,
related_name="+",
to="lnschema_core.user",
),
),
(
"run",
lnschema_core.fields.ForeignKey(
blank=True,
default=lnschema_core.models.current_run,
null=True,
on_delete=django.db.models.deletion.PROTECT,
related_name="+",
to="lnschema_core.run",
),
),
],
options={
"abstract": False,
},
bases=(
lnschema_core.models.CanCurate,
models.Model,
lnschema_core.models.ValidateFields,
),
),
migrations.CreateModel(
name="Project",
fields=[
Expand All @@ -101,6 +244,7 @@ class Migration(migrations.Migration):
"uid",
lnschema_core.fields.CharField(
blank=True,
db_index=True,
default=lnschema_core.ids.base62_12,
max_length=12,
unique=True,
Expand Down Expand Up @@ -136,11 +280,17 @@ class Migration(migrations.Migration):
(
"artifacts",
models.ManyToManyField(
related_name="Projects",
related_name="projects",
through="ourprojects.ArtifactProject",
to="lnschema_core.artifact",
),
),
(
"contributors",
models.ManyToManyField(
related_name="projects", to="ourprojects.person"
),
),
(
"created_by",
lnschema_core.fields.ForeignKey(
Expand Down Expand Up @@ -177,14 +327,175 @@ class Migration(migrations.Migration):
name="project",
field=lnschema_core.fields.ForeignKey(
blank=True,
default=None,
on_delete=django.db.models.deletion.PROTECT,
related_name="links_artifact",
to="ourprojects.project",
),
),
migrations.CreateModel(
name="Reference",
fields=[
(
"created_at",
lnschema_core.fields.DateTimeField(
auto_now_add=True, db_index=True
),
),
(
"updated_at",
lnschema_core.fields.DateTimeField(auto_now=True, db_index=True),
),
("id", models.AutoField(primary_key=True, serialize=False)),
(
"uid",
lnschema_core.fields.CharField(
blank=True,
db_index=True,
default=lnschema_core.ids.base62_12,
max_length=12,
unique=True,
),
),
(
"name",
lnschema_core.fields.CharField(
blank=True, db_index=True, default=None, max_length=255
),
),
(
"abbr",
lnschema_core.fields.CharField(
blank=True,
db_index=True,
default=None,
max_length=32,
null=True,
unique=True,
),
),
("url", lnschema_core.fields.URLField(blank=True, null=True)),
(
"pubmed_id",
lnschema_core.fields.BigIntegerField(
blank=True, db_index=True, null=True
),
),
(
"doi",
lnschema_core.fields.CharField(
blank=True,
db_index=True,
default=None,
max_length=255,
null=True,
validators=[
django.core.validators.RegexValidator(
message="Must be a DOI (e.g., 10.1000/xyz123 or https://doi.org/10.1000/xyz123)",
regex="^(?:https?://(?:dx\\.)?doi\\.org/|doi:|DOI:)?10\\.\\d+/.*$",
)
],
),
),
(
"preprint",
lnschema_core.fields.BooleanField(
blank=True, db_index=True, default=False
),
),
(
"public",
lnschema_core.fields.BooleanField(
blank=True, db_index=True, default=True
),
),
(
"journal",
lnschema_core.fields.TextField(blank=True, default=None, null=True),
),
(
"description",
lnschema_core.fields.TextField(blank=True, default=None, null=True),
),
(
"text",
lnschema_core.fields.TextField(blank=True, default=None, null=True),
),
(
"published_at",
lnschema_core.fields.DateField(blank=True, default=None, null=True),
),
(
"_previous_runs",
models.ManyToManyField(related_name="+", to="lnschema_core.run"),
),
(
"artifacts",
models.ManyToManyField(
related_name="references",
through="ourprojects.ArtifactReference",
to="lnschema_core.artifact",
),
),
(
"authors",
models.ManyToManyField(
related_name="references", to="ourprojects.person"
),
),
(
"created_by",
lnschema_core.fields.ForeignKey(
blank=True,
default=lnschema_core.users.current_user_id,
on_delete=django.db.models.deletion.PROTECT,
related_name="+",
to="lnschema_core.user",
),
),
(
"run",
lnschema_core.fields.ForeignKey(
blank=True,
default=lnschema_core.models.current_run,
null=True,
on_delete=django.db.models.deletion.PROTECT,
related_name="+",
to="lnschema_core.run",
),
),
],
options={
"abstract": False,
},
bases=(
lnschema_core.models.CanCurate,
models.Model,
lnschema_core.models.ValidateFields,
),
),
migrations.AddField(
model_name="project",
name="references",
field=models.ManyToManyField(
related_name="projects", to="ourprojects.reference"
),
),
migrations.AddField(
model_name="artifactreference",
name="reference",
field=lnschema_core.fields.ForeignKey(
blank=True,
on_delete=django.db.models.deletion.PROTECT,
related_name="links_artifact",
to="ourprojects.reference",
),
),
migrations.AlterUniqueTogether(
name="artifactproject",
unique_together={("artifact", "project", "feature")},
),
migrations.AlterUniqueTogether(
name="artifactreference",
unique_together={("artifact", "reference", "feature")},
),
]
Loading

0 comments on commit 37cad62

Please sign in to comment.