Skip to content

Commit

Permalink
Merge pull request #2 from laminlabs/field-defaults
Browse files Browse the repository at this point in the history
🎨 Set `blank=True`
  • Loading branch information
sunnyosun authored Nov 17, 2024
2 parents 77b00f2 + 00beeaf commit a6631e6
Show file tree
Hide file tree
Showing 4 changed files with 180 additions and 16 deletions.
2 changes: 2 additions & 0 deletions ourprojects/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,5 +29,7 @@ def __getattr__(name):


if _check_instance_setup():
import lamindb

del __getattr__ # delete so that imports work out
from .models import Project
2 changes: 1 addition & 1 deletion ourprojects/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -121,7 +121,7 @@ class Migration(migrations.Migration):
options={
"abstract": False,
},
bases=(lnschema_core.models.CanValidate, models.Model),
bases=(lnschema_core.models.CanCurate, models.Model),
),
migrations.AddField(
model_name="artifactproject",
Expand Down
162 changes: 162 additions & 0 deletions ourprojects/migrations/0002_alter_artifactproject_artifact_and_more.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,162 @@
# Generated by Django 5.2 on 2024-11-15 08:55

import django.db.models.deletion
import lnschema_core.fields
import lnschema_core.ids
import lnschema_core.models
import lnschema_core.users
from django.db import migrations, models


class Migration(migrations.Migration):
dependencies = [
(
"lnschema_core",
"0069_alter_artifact__accessor_alter_artifact__hash_type_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="created_at",
field=lnschema_core.fields.DateTimeField(auto_now_add=True, db_index=True),
),
migrations.AlterField(
model_name="artifactproject",
name="created_by",
field=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",
),
),
migrations.AlterField(
model_name="artifactproject",
name="feature",
field=lnschema_core.fields.ForeignKey(
blank=True,
default=None,
null=True,
on_delete=django.db.models.deletion.PROTECT,
related_name="links_artifactproject",
to="lnschema_core.feature",
),
),
migrations.AlterField(
model_name="artifactproject",
name="feature_ref_is_name",
field=lnschema_core.fields.BooleanField(
blank=True, default=None, null=True
),
),
migrations.AlterField(
model_name="artifactproject",
name="label_ref_is_name",
field=lnschema_core.fields.BooleanField(
blank=True, default=None, null=True
),
),
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.AlterField(
model_name="artifactproject",
name="run",
field=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",
),
),
migrations.AlterField(
model_name="project",
name="abbr",
field=lnschema_core.fields.CharField(
blank=True,
db_index=True,
default=None,
max_length=32,
null=True,
unique=True,
),
),
migrations.AlterField(
model_name="project",
name="created_at",
field=lnschema_core.fields.DateTimeField(auto_now_add=True, db_index=True),
),
migrations.AlterField(
model_name="project",
name="created_by",
field=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",
),
),
migrations.AlterField(
model_name="project",
name="name",
field=lnschema_core.fields.CharField(
blank=True, db_index=True, default=None, max_length=255
),
),
migrations.AlterField(
model_name="project",
name="run",
field=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",
),
),
migrations.AlterField(
model_name="project",
name="uid",
field=lnschema_core.fields.CharField(
blank=True,
default=lnschema_core.ids.base62_12,
max_length=12,
unique=True,
),
),
migrations.AlterField(
model_name="project",
name="updated_at",
field=lnschema_core.fields.DateTimeField(auto_now=True, db_index=True),
),
migrations.AlterField(
model_name="project",
name="url",
field=models.URLField(blank=True, default=None, max_length=255, null=True),
),
]
30 changes: 15 additions & 15 deletions ourprojects/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,18 +3,20 @@
from django.db import models
from django.db.models import CASCADE, PROTECT
from lnschema_core import ids
from lnschema_core.fields import BooleanField, CharField, ForeignKey
from lnschema_core.models import (
Artifact,
CanValidate,
CanCurate,
Feature,
LinkORM,
Record,
TracksRun,
TracksUpdates,
ValidateFields,
)


class Project(Record, CanValidate, TracksRun, TracksUpdates):
class Project(Record, CanCurate, TracksRun, TracksUpdates, ValidateFields):
"""Projects.
Example:
Expand All @@ -28,15 +30,17 @@ 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 = models.CharField(unique=True, max_length=12, default=ids.base62_12)
uid: str = CharField(unique=True, max_length=12, default=ids.base62_12)
"""Universal id, valid across DB instances."""
name: str = models.CharField(max_length=255, default=None, db_index=True)
name: str = CharField(max_length=255, default=None, db_index=True)
"""Title or name of the Project."""
abbr: str | None = models.CharField(
abbr: str | None = CharField(
max_length=32, db_index=True, unique=True, null=True, default=None
)
"""A unique abbreviation."""
url: str | None = models.URLField(max_length=255, null=True, default=None)
url: str | None = models.URLField(
max_length=255, null=True, default=None, blank=True
)
"""A URL to view."""
artifacts: Artifact = models.ManyToManyField(
Artifact, through="ArtifactProject", related_name="Projects"
Expand All @@ -46,21 +50,17 @@ class Meta(Record.Meta, TracksRun.Meta, TracksUpdates.Meta):

class ArtifactProject(Record, LinkORM, TracksRun):
id: int = models.BigAutoField(primary_key=True)
artifact: Artifact = models.ForeignKey(
Artifact, CASCADE, related_name="links_project"
)
project: Project = models.ForeignKey(
Project, PROTECT, related_name="links_artifact"
)
feature: Feature = models.ForeignKey(
artifact: Artifact = ForeignKey(Artifact, CASCADE, related_name="links_project")
project: Project = ForeignKey(Project, PROTECT, related_name="links_artifact")
feature: Feature = ForeignKey(
Feature,
PROTECT,
null=True,
default=None,
related_name="links_artifactproject",
)
label_ref_is_name: bool | None = models.BooleanField(null=True, default=None)
feature_ref_is_name: bool | None = models.BooleanField(null=True, default=None)
label_ref_is_name: bool | None = BooleanField(null=True, default=None)
feature_ref_is_name: bool | None = BooleanField(null=True, default=None)

class Meta:
# can have the same label linked to the same artifact if the feature is
Expand Down

0 comments on commit a6631e6

Please sign in to comment.