Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

🎨 Add blank=True #2

Merged
merged 3 commits into from
Nov 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions cellregistry/__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 Cell
2 changes: 1 addition & 1 deletion cellregistry/migrations/0001_initial.py
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
Original file line number Diff line number Diff line change
@@ -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),
),
]
31 changes: 14 additions & 17 deletions cellregistry/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,9 +4,10 @@
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,
CanCurate,
Feature,
LinkORM,
Record,
Expand All @@ -16,7 +17,7 @@
)


class Cell(Record, CanValidate, TracksRun, TracksUpdates):
class Cell(Record, CanCurate, TracksRun, TracksUpdates):
"""Single cells.

Example:
Expand All @@ -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
Expand All @@ -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"
Expand All @@ -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"
)
Loading