From 92b024262b9aa6729b89a6162973fa8a3b4b5189 Mon Sep 17 00:00:00 2001 From: Sunny Sun <38218185+sunnyosun@users.noreply.github.com> Date: Fri, 15 Nov 2024 09:58:21 +0100 Subject: [PATCH 1/5] Set blank=True --- ...alter_artifactproject_artifact_and_more.py | 163 ++++++++++++++++++ ourprojects/models.py | 25 ++- 2 files changed, 175 insertions(+), 13 deletions(-) create mode 100644 ourprojects/migrations/0002_alter_artifactproject_artifact_and_more.py diff --git a/ourprojects/migrations/0002_alter_artifactproject_artifact_and_more.py b/ourprojects/migrations/0002_alter_artifactproject_artifact_and_more.py new file mode 100644 index 0000000..c501f01 --- /dev/null +++ b/ourprojects/migrations/0002_alter_artifactproject_artifact_and_more.py @@ -0,0 +1,163 @@ +# 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), + ), + ] diff --git a/ourprojects/models.py b/ourprojects/models.py index 6a4a8cc..f45e1a3 100644 --- a/ourprojects/models.py +++ b/ourprojects/models.py @@ -12,6 +12,7 @@ TracksRun, TracksUpdates, ) +from lnschema_core.fields import CharField, ForeignKey, BooleanField class Project(Record, CanValidate, TracksRun, TracksUpdates): @@ -28,15 +29,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" @@ -46,21 +49,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 From b39e71ca82fd5f14ebd539f501a6ec7698aabdb6 Mon Sep 17 00:00:00 2001 From: Sunny Sun <38218185+sunnyosun@users.noreply.github.com> Date: Fri, 15 Nov 2024 09:58:57 +0100 Subject: [PATCH 2/5] Set blank=True --- .../migrations/0002_alter_artifactproject_artifact_and_more.py | 1 - ourprojects/models.py | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/ourprojects/migrations/0002_alter_artifactproject_artifact_and_more.py b/ourprojects/migrations/0002_alter_artifactproject_artifact_and_more.py index c501f01..122484e 100644 --- a/ourprojects/migrations/0002_alter_artifactproject_artifact_and_more.py +++ b/ourprojects/migrations/0002_alter_artifactproject_artifact_and_more.py @@ -9,7 +9,6 @@ class Migration(migrations.Migration): - dependencies = [ ( "lnschema_core", diff --git a/ourprojects/models.py b/ourprojects/models.py index f45e1a3..9b2bf79 100644 --- a/ourprojects/models.py +++ b/ourprojects/models.py @@ -3,6 +3,7 @@ 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, @@ -12,7 +13,6 @@ TracksRun, TracksUpdates, ) -from lnschema_core.fields import CharField, ForeignKey, BooleanField class Project(Record, CanValidate, TracksRun, TracksUpdates): From 7d8f49329cd6f3229c31650b88c2e96c28bbf71a Mon Sep 17 00:00:00 2001 From: Sunny Sun <38218185+sunnyosun@users.noreply.github.com> Date: Fri, 15 Nov 2024 15:18:56 +0100 Subject: [PATCH 3/5] =?UTF-8?q?=F0=9F=8E=A8=20Introduce=20ValidateFields?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ourprojects/models.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/ourprojects/models.py b/ourprojects/models.py index 9b2bf79..70e56de 100644 --- a/ourprojects/models.py +++ b/ourprojects/models.py @@ -12,10 +12,11 @@ Record, TracksRun, TracksUpdates, + ValidateFields, ) -class Project(Record, CanValidate, TracksRun, TracksUpdates): +class Project(Record, CanValidate, TracksRun, TracksUpdates, ValidateFields): """Projects. Example: From a64d4358ef023c44af6387aef5f0d1500b8f5ec0 Mon Sep 17 00:00:00 2001 From: Sunny Sun <38218185+sunnyosun@users.noreply.github.com> Date: Fri, 15 Nov 2024 16:10:29 +0100 Subject: [PATCH 4/5] =?UTF-8?q?=F0=9F=9A=9A=20Rename=20CanValidate=20to=20?= =?UTF-8?q?CanCurate?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ourprojects/migrations/0001_initial.py | 2 +- ourprojects/models.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/ourprojects/migrations/0001_initial.py b/ourprojects/migrations/0001_initial.py index 6053d20..0047850 100644 --- a/ourprojects/migrations/0001_initial.py +++ b/ourprojects/migrations/0001_initial.py @@ -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", diff --git a/ourprojects/models.py b/ourprojects/models.py index 70e56de..aa384d3 100644 --- a/ourprojects/models.py +++ b/ourprojects/models.py @@ -6,7 +6,7 @@ from lnschema_core.fields import BooleanField, CharField, ForeignKey from lnschema_core.models import ( Artifact, - CanValidate, + CanCurate, Feature, LinkORM, Record, @@ -16,7 +16,7 @@ ) -class Project(Record, CanValidate, TracksRun, TracksUpdates, ValidateFields): +class Project(Record, CanCurate, TracksRun, TracksUpdates, ValidateFields): """Projects. Example: From 00beeafb977f76090f96d4d2bdcee8c2ee57df22 Mon Sep 17 00:00:00 2001 From: Sunny Sun <38218185+sunnyosun@users.noreply.github.com> Date: Sun, 17 Nov 2024 13:01:52 +0100 Subject: [PATCH 5/5] =?UTF-8?q?=F0=9F=8E=A8=20Import=20lamindb?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ourprojects/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/ourprojects/__init__.py b/ourprojects/__init__.py index 748d0f6..423fead 100644 --- a/ourprojects/__init__.py +++ b/ourprojects/__init__.py @@ -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