From eb8e377427598843ad6d58bc7a451dead9fe7ca7 Mon Sep 17 00:00:00 2001 From: Sunny Sun <38218185+sunnyosun@users.noreply.github.com> Date: Fri, 15 Nov 2024 15:17:00 +0100 Subject: [PATCH 1/3] =?UTF-8?q?=F0=9F=8E=A8=20Add=20blank=3DTrue?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...tifact_alter_artifactcell_cell_and_more.py | 126 ++++++++++++++++++ cellregistry/models.py | 27 ++-- 2 files changed, 138 insertions(+), 15 deletions(-) create mode 100644 cellregistry/migrations/0002_alter_artifactcell_artifact_alter_artifactcell_cell_and_more.py diff --git a/cellregistry/migrations/0002_alter_artifactcell_artifact_alter_artifactcell_cell_and_more.py b/cellregistry/migrations/0002_alter_artifactcell_artifact_alter_artifactcell_cell_and_more.py new file mode 100644 index 0000000..9f5508b --- /dev/null +++ b/cellregistry/migrations/0002_alter_artifactcell_artifact_alter_artifactcell_cell_and_more.py @@ -0,0 +1,126 @@ +# Generated by Django 5.2 on 2024-11-15 14:16 + +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 + + +class Migration(migrations.Migration): + dependencies = [ + ("cellregistry", "0001_initial"), + ( + "lnschema_core", + "0069_alter_artifact__accessor_alter_artifact__hash_type_and_more", + ), + ] + + operations = [ + migrations.AlterField( + model_name="artifactcell", + name="artifact", + field=lnschema_core.fields.ForeignKey( + blank=True, + on_delete=django.db.models.deletion.CASCADE, + related_name="links_cell", + to="lnschema_core.artifact", + ), + ), + migrations.AlterField( + model_name="artifactcell", + name="cell", + field=lnschema_core.fields.ForeignKey( + blank=True, + on_delete=django.db.models.deletion.CASCADE, + related_name="links_artifact", + to="cellregistry.cell", + ), + ), + migrations.AlterField( + model_name="artifactcell", + name="created_at", + field=lnschema_core.fields.DateTimeField(auto_now_add=True, db_index=True), + ), + migrations.AlterField( + model_name="artifactcell", + 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="artifactcell", + 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="cell", + name="created_at", + field=lnschema_core.fields.DateTimeField(auto_now_add=True, db_index=True), + ), + migrations.AlterField( + model_name="cell", + 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="cell", + name="description", + field=lnschema_core.fields.CharField( + blank=True, db_index=True, default=None, max_length=255, null=True + ), + ), + migrations.AlterField( + model_name="cell", + name="name", + field=lnschema_core.fields.CharField( + blank=True, db_index=True, default=None, max_length=255, unique=True + ), + ), + migrations.AlterField( + model_name="cell", + 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="cell", + name="uid", + field=lnschema_core.fields.CharField( + blank=True, + default=lnschema_core.ids.base62_20, + max_length=20, + unique=True, + ), + ), + migrations.AlterField( + model_name="cell", + name="updated_at", + field=lnschema_core.fields.DateTimeField(auto_now=True, db_index=True), + ), + ] diff --git a/cellregistry/models.py b/cellregistry/models.py index 43792b5..f672bda 100644 --- a/cellregistry/models.py +++ b/cellregistry/models.py @@ -4,6 +4,7 @@ from django.db import models from django.db.models import CASCADE, PROTECT from lnschema_core import ids +from lnschema_core.fields import CharField, ForeignKey from lnschema_core.models import ( Artifact, CanValidate, @@ -30,11 +31,9 @@ class Meta(Record.Meta, TracksRun.Meta, TracksUpdates.Meta): id: int = models.BigAutoField(primary_key=True) """Internal id, valid only in one DB instance.""" - uid: str = models.CharField(unique=True, max_length=20, default=ids.base62_20) + uid: str = CharField(unique=True, max_length=20, default=ids.base62_20) """Universal id, valid across DB instances.""" - name: str = models.CharField( - max_length=255, default=None, unique=True, db_index=True - ) + name: str = CharField(max_length=255, default=None, unique=True, db_index=True) """A unique name for the cell. It's typically the barcode combined with an identifier for the dataset that @@ -47,9 +46,7 @@ class Meta(Record.Meta, TracksRun.Meta, TracksUpdates.Meta): Pan_T7935494_ATCATGGTCTACCTGC """ - description: str = models.CharField( - max_length=255, db_index=True, null=True, default=None - ) + description: str = CharField(max_length=255, db_index=True, null=True, default=None) """A description.""" # ulabels: ULabel = models.ManyToManyField( # ULabel, through="CellULabel", related_name="cells" @@ -67,24 +64,24 @@ class Meta(Record.Meta, TracksRun.Meta, TracksUpdates.Meta): class ArtifactCell(Record, LinkORM, TracksRun): id: int = models.BigAutoField(primary_key=True) - artifact: Artifact = models.ForeignKey(Artifact, CASCADE, related_name="links_cell") - cell: Cell = models.ForeignKey(Cell, CASCADE, related_name="links_artifact") + artifact: Artifact = ForeignKey(Artifact, CASCADE, related_name="links_cell") + cell: Cell = ForeignKey(Cell, CASCADE, related_name="links_artifact") class CellCellType: id: int = models.BigAutoField(primary_key=True) - cell: Cell = models.ForeignKey(Cell, CASCADE, related_name="links_cell_type") + cell: Cell = ForeignKey(Cell, CASCADE, related_name="links_cell_type") # follow the .lower() convention in link models - celltype: CellType = models.ForeignKey(CellType, PROTECT, related_name="links_cell") - feature: Feature = models.ForeignKey( + celltype: CellType = ForeignKey(CellType, PROTECT, related_name="links_cell") + feature: Feature = ForeignKey( Feature, PROTECT, null=True, default=None, related_name="links_cellcelltype" ) class CellULabel: id: int = models.BigAutoField(primary_key=True) - cell: Cell = models.ForeignKey(Cell, CASCADE, related_name="links_ulabel") - ulabel: ULabel = models.ForeignKey(ULabel, PROTECT, related_name="links_cell") - feature: Feature = models.ForeignKey( + cell: Cell = ForeignKey(Cell, CASCADE, related_name="links_ulabel") + ulabel: ULabel = ForeignKey(ULabel, PROTECT, related_name="links_cell") + feature: Feature = ForeignKey( Feature, PROTECT, null=True, default=None, related_name="links_cellulabel" ) From 6a528df8184f04941dbb9633028799b5061b7639 Mon Sep 17 00:00:00 2001 From: Sunny Sun <38218185+sunnyosun@users.noreply.github.com> Date: Fri, 15 Nov 2024 15:47:54 +0100 Subject: [PATCH 2/3] =?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 --- cellregistry/migrations/0001_initial.py | 2 +- cellregistry/models.py | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/cellregistry/migrations/0001_initial.py b/cellregistry/migrations/0001_initial.py index fa8ba16..b7e482b 100644 --- a/cellregistry/migrations/0001_initial.py +++ b/cellregistry/migrations/0001_initial.py @@ -66,7 +66,7 @@ class Migration(migrations.Migration): options={ "abstract": False, }, - bases=(lnschema_core.models.CanValidate, models.Model), + bases=(lnschema_core.models.CanCurate, models.Model), ), migrations.CreateModel( name="ArtifactCell", diff --git a/cellregistry/models.py b/cellregistry/models.py index f672bda..4bcbe89 100644 --- a/cellregistry/models.py +++ b/cellregistry/models.py @@ -7,7 +7,7 @@ from lnschema_core.fields import CharField, ForeignKey from lnschema_core.models import ( Artifact, - CanValidate, + CanCurate, Feature, LinkORM, Record, @@ -17,7 +17,7 @@ ) -class Cell(Record, CanValidate, TracksRun, TracksUpdates): +class Cell(Record, CanCurate, TracksRun, TracksUpdates): """Single cells. Example: From 284b414469f93dc7c510418edfe9fb9cab002bf0 Mon Sep 17 00:00:00 2001 From: Sunny Sun <38218185+sunnyosun@users.noreply.github.com> Date: Sun, 17 Nov 2024 13:00:56 +0100 Subject: [PATCH 3/3] =?UTF-8?q?=F0=9F=8E=A8=20Import=20lamindb?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- cellregistry/__init__.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/cellregistry/__init__.py b/cellregistry/__init__.py index c8451f0..70b4101 100644 --- a/cellregistry/__init__.py +++ b/cellregistry/__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 Cell