diff --git a/apis_ontology/management/commands/import_entities.py b/apis_ontology/management/commands/import_entities.py index 5180387..5a1a997 100644 --- a/apis_ontology/management/commands/import_entities.py +++ b/apis_ontology/management/commands/import_entities.py @@ -1,8 +1,6 @@ import logging -from pprint import pprint import pandas as pd -from apis_ontology.models import Place from django.apps import apps from django.core.management.base import BaseCommand from tqdm.auto import tqdm @@ -10,6 +8,8 @@ logger = logging.getLogger(__name__) pd.set_option("display.max_colwidth", None) +ENTITY_MODELS = ["person", "place", "instance", "work"] + class Command(BaseCommand): """ @@ -18,35 +18,43 @@ class Command(BaseCommand): import_file = "data/dump_test.json" + def add_arguments(self, parser): + parser.add_argument("args", nargs="*", type=str) + def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) + self.df = pd.read_json(self.import_file) self.df = self.df[self.df.model != "apis_metainfo.uri"] logger.debug("Columns: %s", self.df.columns) logger.debug("Number of rows: %d", self.df.shape[0]) logger.debug("Models: %s", self.df.model.unique()) - Place.objects.all().delete() def handle(self, *args, **kwargs): """ parses the data dump from the old schema and imports it into the current schema """ + if not args: + logging.error("Please enter the names of entity models to import") + return def get_entity_data(model_name): - ENTITY_MODELS = ["person", "place", "instance", "work"] if model_name not in ENTITY_MODELS: logging.error( "%s is unknown. Expecting one of %s", model_name, ENTITY_MODELS ) - enitity_rows = self.df[self.df.model == f"apis_ontology.{model_name}"] - logging.debug("Found %d rows of type %s", enitity_rows.shape[0], model_name) + entity_rows = self.df[self.df.model == f"apis_ontology.{model_name}"] + logging.debug("Found %d rows of type %s", entity_rows.shape[0], model_name) other_fields = {} - for _, row in tqdm(enitity_rows.iterrows(), total=enitity_rows.shape[0]): + for _, row in tqdm(entity_rows.iterrows(), total=entity_rows.shape[0]): # get data from root object other_object_info = self.df[ (self.df.pk == row.pk) & (self.df.model != row.model) ] for _, extra_fields in other_object_info.iterrows(): + if extra_fields.model.startswith("apis_ontology"): + continue + other_fields = {**other_fields, **extra_fields.fields} field_values = { @@ -72,4 +80,9 @@ def get_entity_data(model_name): model_object = model_class(**field_values) model_object.save() - df = get_entity_data("place") + for arg in args: + if arg not in ENTITY_MODELS: + logging.error("Unrecognised entity type %s for import", arg) + break + + get_entity_data(arg) diff --git a/apis_ontology/migrations/0002_person_versionperson_versionperson_collection.py b/apis_ontology/migrations/0002_person_versionperson_versionperson_collection.py new file mode 100644 index 0000000..9312d49 --- /dev/null +++ b/apis_ontology/migrations/0002_person_versionperson_versionperson_collection.py @@ -0,0 +1,320 @@ +# Generated by Django 4.2.11 on 2024-04-22 05:57 + +import apis_core.generic.abc +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion +import simple_history.models + + +class Migration(migrations.Migration): + + dependencies = [ + ("apis_metainfo", "0012_remove_rootobject_deprecated_name"), + ("contenttypes", "0002_remove_content_type_name"), + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ("apis_ontology", "0001_initial"), + ] + + operations = [ + migrations.CreateModel( + name="Person", + fields=[ + ( + "rootobject_ptr", + models.OneToOneField( + auto_created=True, + on_delete=django.db.models.deletion.CASCADE, + parent_link=True, + primary_key=True, + serialize=False, + to="apis_metainfo.rootobject", + ), + ), + ("start_date", models.DateField(blank=True, editable=False, null=True)), + ( + "start_start_date", + models.DateField(blank=True, editable=False, null=True), + ), + ( + "start_end_date", + models.DateField(blank=True, editable=False, null=True), + ), + ("end_date", models.DateField(blank=True, editable=False, null=True)), + ( + "end_start_date", + models.DateField(blank=True, editable=False, null=True), + ), + ( + "end_end_date", + models.DateField(blank=True, editable=False, null=True), + ), + ( + "start_date_written", + models.CharField( + blank=True, max_length=255, null=True, verbose_name="Start" + ), + ), + ( + "end_date_written", + models.CharField( + blank=True, max_length=255, null=True, verbose_name="End" + ), + ), + ( + "alternative_names", + models.TextField( + blank=True, null=True, verbose_name="Alternative names" + ), + ), + ( + "external_links", + models.TextField( + blank=True, null=True, verbose_name="External links" + ), + ), + ( + "review", + models.BooleanField( + default=False, + help_text="Should be set to True, if the data record holds up quality standards.", + ), + ), + ( + "notes", + models.TextField(blank=True, null=True, verbose_name="Notes"), + ), + ("published", models.BooleanField(default=False)), + ( + "name", + models.CharField( + blank=True, default="", max_length=255, verbose_name="Name" + ), + ), + ( + "gender", + models.CharField( + choices=[("male", "Male"), ("female", "Female")], + default="male", + max_length=6, + ), + ), + ( + "nationality", + models.CharField( + blank=True, + choices=[("Indic", "Indic"), ("Tibetan", "Tibetan")], + max_length=10, + null=True, + ), + ), + ("comments", models.TextField(blank=True, null=True)), + ( + "collection", + models.ManyToManyField( + editable=False, to="apis_metainfo.collection" + ), + ), + ], + options={ + "abstract": False, + }, + bases=("apis_metainfo.rootobject", models.Model), + ), + migrations.CreateModel( + name="VersionPerson", + fields=[ + ( + "rootobject_ptr", + models.ForeignKey( + auto_created=True, + blank=True, + db_constraint=False, + null=True, + on_delete=django.db.models.deletion.DO_NOTHING, + parent_link=True, + related_name="+", + to="apis_metainfo.rootobject", + ), + ), + ( + "id", + models.IntegerField( + auto_created=True, blank=True, db_index=True, verbose_name="ID" + ), + ), + ("start_date", models.DateField(blank=True, editable=False, null=True)), + ( + "start_start_date", + models.DateField(blank=True, editable=False, null=True), + ), + ( + "start_end_date", + models.DateField(blank=True, editable=False, null=True), + ), + ("end_date", models.DateField(blank=True, editable=False, null=True)), + ( + "end_start_date", + models.DateField(blank=True, editable=False, null=True), + ), + ( + "end_end_date", + models.DateField(blank=True, editable=False, null=True), + ), + ( + "start_date_written", + models.CharField( + blank=True, max_length=255, null=True, verbose_name="Start" + ), + ), + ( + "end_date_written", + models.CharField( + blank=True, max_length=255, null=True, verbose_name="End" + ), + ), + ( + "version_tag", + models.CharField(blank=True, max_length=255, null=True), + ), + ( + "alternative_names", + models.TextField( + blank=True, null=True, verbose_name="Alternative names" + ), + ), + ( + "external_links", + models.TextField( + blank=True, null=True, verbose_name="External links" + ), + ), + ( + "review", + models.BooleanField( + default=False, + help_text="Should be set to True, if the data record holds up quality standards.", + ), + ), + ( + "notes", + models.TextField(blank=True, null=True, verbose_name="Notes"), + ), + ("published", models.BooleanField(default=False)), + ( + "name", + models.CharField( + blank=True, default="", max_length=255, verbose_name="Name" + ), + ), + ( + "gender", + models.CharField( + choices=[("male", "Male"), ("female", "Female")], + default="male", + max_length=6, + ), + ), + ( + "nationality", + models.CharField( + blank=True, + choices=[("Indic", "Indic"), ("Tibetan", "Tibetan")], + max_length=10, + null=True, + ), + ), + ("comments", models.TextField(blank=True, null=True)), + ("history_id", models.AutoField(primary_key=True, serialize=False)), + ("history_date", models.DateTimeField(db_index=True)), + ("history_change_reason", models.CharField(max_length=100, null=True)), + ( + "history_type", + models.CharField( + choices=[("+", "Created"), ("~", "Changed"), ("-", "Deleted")], + max_length=1, + ), + ), + ( + "history_user", + models.ForeignKey( + null=True, + on_delete=django.db.models.deletion.SET_NULL, + related_name="+", + to=settings.AUTH_USER_MODEL, + ), + ), + ( + "self_contenttype", + models.ForeignKey( + blank=True, + db_constraint=False, + editable=False, + null=True, + on_delete=django.db.models.deletion.DO_NOTHING, + related_name="+", + to="contenttypes.contenttype", + ), + ), + ], + options={ + "verbose_name": "Version", + "verbose_name_plural": "Versions", + "ordering": ("-history_date", "-history_id"), + "get_latest_by": ("history_date", "history_id"), + }, + bases=( + simple_history.models.HistoricalChanges, + models.Model, + apis_core.generic.abc.GenericModel, + ), + ), + migrations.CreateModel( + name="VersionPerson_collection", + fields=[ + ( + "id", + models.IntegerField( + auto_created=True, blank=True, db_index=True, verbose_name="ID" + ), + ), + ("m2m_history_id", models.AutoField(primary_key=True, serialize=False)), + ( + "collection", + models.ForeignKey( + blank=True, + db_constraint=False, + db_tablespace="", + null=True, + on_delete=django.db.models.deletion.DO_NOTHING, + related_name="+", + to="apis_metainfo.collection", + ), + ), + ( + "history", + models.ForeignKey( + db_constraint=False, + on_delete=django.db.models.deletion.DO_NOTHING, + to="apis_ontology.versionperson", + ), + ), + ( + "person", + models.ForeignKey( + blank=True, + db_constraint=False, + db_tablespace="", + null=True, + on_delete=django.db.models.deletion.DO_NOTHING, + related_name="+", + to="apis_ontology.person", + ), + ), + ], + options={ + "verbose_name": "VersionPerson_collection", + }, + bases=(simple_history.models.HistoricalChanges, models.Model), + ), + ] diff --git a/apis_ontology/migrations/0003_alter_person_options.py b/apis_ontology/migrations/0003_alter_person_options.py new file mode 100644 index 0000000..bab74a6 --- /dev/null +++ b/apis_ontology/migrations/0003_alter_person_options.py @@ -0,0 +1,17 @@ +# Generated by Django 4.2.11 on 2024-04-22 06:22 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ("apis_ontology", "0002_person_versionperson_versionperson_collection"), + ] + + operations = [ + migrations.AlterModelOptions( + name="person", + options={"verbose_name": "person", "verbose_name_plural": "Persons"}, + ), + ] diff --git a/apis_ontology/migrations/0004_versionwork_work_versionwork_collection.py b/apis_ontology/migrations/0004_versionwork_work_versionwork_collection.py new file mode 100644 index 0000000..228b245 --- /dev/null +++ b/apis_ontology/migrations/0004_versionwork_work_versionwork_collection.py @@ -0,0 +1,353 @@ +# Generated by Django 4.2.11 on 2024-04-22 06:24 + +import apis_core.generic.abc +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion +import simple_history.models + + +class Migration(migrations.Migration): + + dependencies = [ + ("apis_metainfo", "0012_remove_rootobject_deprecated_name"), + ("contenttypes", "0002_remove_content_type_name"), + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ("apis_ontology", "0003_alter_person_options"), + ] + + operations = [ + migrations.CreateModel( + name="VersionWork", + fields=[ + ( + "rootobject_ptr", + models.ForeignKey( + auto_created=True, + blank=True, + db_constraint=False, + null=True, + on_delete=django.db.models.deletion.DO_NOTHING, + parent_link=True, + related_name="+", + to="apis_metainfo.rootobject", + ), + ), + ( + "id", + models.IntegerField( + auto_created=True, blank=True, db_index=True, verbose_name="ID" + ), + ), + ("start_date", models.DateField(blank=True, editable=False, null=True)), + ( + "start_start_date", + models.DateField(blank=True, editable=False, null=True), + ), + ( + "start_end_date", + models.DateField(blank=True, editable=False, null=True), + ), + ("end_date", models.DateField(blank=True, editable=False, null=True)), + ( + "end_start_date", + models.DateField(blank=True, editable=False, null=True), + ), + ( + "end_end_date", + models.DateField(blank=True, editable=False, null=True), + ), + ( + "start_date_written", + models.CharField( + blank=True, max_length=255, null=True, verbose_name="Start" + ), + ), + ( + "end_date_written", + models.CharField( + blank=True, max_length=255, null=True, verbose_name="End" + ), + ), + ( + "version_tag", + models.CharField(blank=True, max_length=255, null=True), + ), + ("comments", models.TextField(blank=True, null=True)), + ( + "alternative_names", + models.TextField( + blank=True, null=True, verbose_name="Alternative names" + ), + ), + ( + "external_links", + models.TextField( + blank=True, null=True, verbose_name="External links" + ), + ), + ( + "review", + models.BooleanField( + default=False, + help_text="Should be set to True, if the data record holds up quality standards.", + ), + ), + ( + "notes", + models.TextField(blank=True, null=True, verbose_name="Notes"), + ), + ("published", models.BooleanField(default=False)), + ( + "subject", + models.CharField( + blank=True, max_length=255, null=True, verbose_name="subject" + ), + ), + ( + "name", + models.CharField( + blank=True, default="", max_length=255, verbose_name="Name" + ), + ), + ( + "sde_dge_ref", + models.CharField( + blank=True, + max_length=25, + null=True, + verbose_name="Derge reference", + ), + ), + ( + "original_language", + models.CharField( + blank=True, + choices=[ + ("Sanskrit", "Sanskrit"), + ("Tibetan", "Tibetan"), + ("Tangut", "Tangut"), + ("Other", "Other"), + ], + max_length=10, + null=True, + ), + ), + ( + "isExtant", + models.BooleanField(default=True, verbose_name="Is extant"), + ), + ("history_id", models.AutoField(primary_key=True, serialize=False)), + ("history_date", models.DateTimeField(db_index=True)), + ("history_change_reason", models.CharField(max_length=100, null=True)), + ( + "history_type", + models.CharField( + choices=[("+", "Created"), ("~", "Changed"), ("-", "Deleted")], + max_length=1, + ), + ), + ( + "history_user", + models.ForeignKey( + null=True, + on_delete=django.db.models.deletion.SET_NULL, + related_name="+", + to=settings.AUTH_USER_MODEL, + ), + ), + ( + "self_contenttype", + models.ForeignKey( + blank=True, + db_constraint=False, + editable=False, + null=True, + on_delete=django.db.models.deletion.DO_NOTHING, + related_name="+", + to="contenttypes.contenttype", + ), + ), + ], + options={ + "verbose_name": "Version", + "verbose_name_plural": "Versions", + "ordering": ("-history_date", "-history_id"), + "get_latest_by": ("history_date", "history_id"), + }, + bases=( + simple_history.models.HistoricalChanges, + models.Model, + apis_core.generic.abc.GenericModel, + ), + ), + migrations.CreateModel( + name="Work", + fields=[ + ( + "rootobject_ptr", + models.OneToOneField( + auto_created=True, + on_delete=django.db.models.deletion.CASCADE, + parent_link=True, + primary_key=True, + serialize=False, + to="apis_metainfo.rootobject", + ), + ), + ("start_date", models.DateField(blank=True, editable=False, null=True)), + ( + "start_start_date", + models.DateField(blank=True, editable=False, null=True), + ), + ( + "start_end_date", + models.DateField(blank=True, editable=False, null=True), + ), + ("end_date", models.DateField(blank=True, editable=False, null=True)), + ( + "end_start_date", + models.DateField(blank=True, editable=False, null=True), + ), + ( + "end_end_date", + models.DateField(blank=True, editable=False, null=True), + ), + ( + "start_date_written", + models.CharField( + blank=True, max_length=255, null=True, verbose_name="Start" + ), + ), + ( + "end_date_written", + models.CharField( + blank=True, max_length=255, null=True, verbose_name="End" + ), + ), + ("comments", models.TextField(blank=True, null=True)), + ( + "alternative_names", + models.TextField( + blank=True, null=True, verbose_name="Alternative names" + ), + ), + ( + "external_links", + models.TextField( + blank=True, null=True, verbose_name="External links" + ), + ), + ( + "review", + models.BooleanField( + default=False, + help_text="Should be set to True, if the data record holds up quality standards.", + ), + ), + ( + "notes", + models.TextField(blank=True, null=True, verbose_name="Notes"), + ), + ("published", models.BooleanField(default=False)), + ( + "subject", + models.CharField( + blank=True, max_length=255, null=True, verbose_name="subject" + ), + ), + ( + "name", + models.CharField( + blank=True, default="", max_length=255, verbose_name="Name" + ), + ), + ( + "sde_dge_ref", + models.CharField( + blank=True, + max_length=25, + null=True, + verbose_name="Derge reference", + ), + ), + ( + "original_language", + models.CharField( + blank=True, + choices=[ + ("Sanskrit", "Sanskrit"), + ("Tibetan", "Tibetan"), + ("Tangut", "Tangut"), + ("Other", "Other"), + ], + max_length=10, + null=True, + ), + ), + ( + "isExtant", + models.BooleanField(default=True, verbose_name="Is extant"), + ), + ( + "collection", + models.ManyToManyField( + editable=False, to="apis_metainfo.collection" + ), + ), + ], + options={ + "verbose_name": "work", + "verbose_name_plural": "Works", + }, + bases=("apis_metainfo.rootobject", models.Model), + ), + migrations.CreateModel( + name="VersionWork_collection", + fields=[ + ( + "id", + models.IntegerField( + auto_created=True, blank=True, db_index=True, verbose_name="ID" + ), + ), + ("m2m_history_id", models.AutoField(primary_key=True, serialize=False)), + ( + "collection", + models.ForeignKey( + blank=True, + db_constraint=False, + db_tablespace="", + null=True, + on_delete=django.db.models.deletion.DO_NOTHING, + related_name="+", + to="apis_metainfo.collection", + ), + ), + ( + "history", + models.ForeignKey( + db_constraint=False, + on_delete=django.db.models.deletion.DO_NOTHING, + to="apis_ontology.versionwork", + ), + ), + ( + "work", + models.ForeignKey( + blank=True, + db_constraint=False, + db_tablespace="", + null=True, + on_delete=django.db.models.deletion.DO_NOTHING, + related_name="+", + to="apis_ontology.work", + ), + ), + ], + options={ + "verbose_name": "VersionWork_collection", + }, + bases=(simple_history.models.HistoricalChanges, models.Model), + ), + ] diff --git a/apis_ontology/migrations/0005_instance_versioninstance_versioninstance_collection.py b/apis_ontology/migrations/0005_instance_versioninstance_versioninstance_collection.py new file mode 100644 index 0000000..ae0ff18 --- /dev/null +++ b/apis_ontology/migrations/0005_instance_versioninstance_versioninstance_collection.py @@ -0,0 +1,436 @@ +# Generated by Django 4.2.11 on 2024-04-22 06:37 + +import apis_core.generic.abc +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion +import simple_history.models + + +class Migration(migrations.Migration): + + dependencies = [ + ("apis_metainfo", "0012_remove_rootobject_deprecated_name"), + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ("contenttypes", "0002_remove_content_type_name"), + ("apis_ontology", "0004_versionwork_work_versionwork_collection"), + ] + + operations = [ + migrations.CreateModel( + name="Instance", + fields=[ + ( + "rootobject_ptr", + models.OneToOneField( + auto_created=True, + on_delete=django.db.models.deletion.CASCADE, + parent_link=True, + primary_key=True, + serialize=False, + to="apis_metainfo.rootobject", + ), + ), + ("start_date", models.DateField(blank=True, editable=False, null=True)), + ( + "start_start_date", + models.DateField(blank=True, editable=False, null=True), + ), + ( + "start_end_date", + models.DateField(blank=True, editable=False, null=True), + ), + ("end_date", models.DateField(blank=True, editable=False, null=True)), + ( + "end_start_date", + models.DateField(blank=True, editable=False, null=True), + ), + ( + "end_end_date", + models.DateField(blank=True, editable=False, null=True), + ), + ( + "start_date_written", + models.CharField( + blank=True, max_length=255, null=True, verbose_name="Start" + ), + ), + ( + "end_date_written", + models.CharField( + blank=True, max_length=255, null=True, verbose_name="End" + ), + ), + ("comments", models.TextField(blank=True, null=True)), + ( + "alternative_names", + models.TextField( + blank=True, null=True, verbose_name="Alternative names" + ), + ), + ( + "external_links", + models.TextField( + blank=True, null=True, verbose_name="External links" + ), + ), + ( + "review", + models.BooleanField( + default=False, + help_text="Should be set to True, if the data record holds up quality standards.", + ), + ), + ( + "notes", + models.TextField(blank=True, null=True, verbose_name="Notes"), + ), + ("published", models.BooleanField(default=False)), + ( + "name", + models.CharField( + blank=True, default="", max_length=255, verbose_name="Name" + ), + ), + ( + "set_num", + models.CharField( + blank=True, + choices=[ + ("Set 1", "Set 1"), + ("Set 2", "Set 2"), + ("Set 3", "Set 3"), + ("Set 4", "Set 4"), + ], + max_length=5, + null=True, + verbose_name="Set", + ), + ), + ("volume", models.CharField(blank=True, max_length=255, null=True)), + ( + "sb_text_number", + models.TextField( + blank=True, + null=True, + verbose_name="Number ascribed to item by Tibschol", + ), + ), + ( + "pp_kdsb", + models.CharField( + blank=True, + max_length=255, + null=True, + verbose_name="Page numbers in print", + ), + ), + ( + "num_folios", + models.CharField( + blank=True, + max_length=255, + null=True, + verbose_name="Number of folios", + ), + ), + ( + "signature_letter", + models.CharField( + blank=True, + max_length=255, + null=True, + verbose_name="Signature letter (category)", + ), + ), + ( + "signature_number", + models.CharField( + blank=True, + max_length=255, + null=True, + verbose_name="Signature number", + ), + ), + ( + "drepung_number", + models.CharField( + blank=True, + max_length=255, + null=True, + verbose_name="Drepung catalogue number", + ), + ), + ( + "provenance", + models.CharField( + blank=True, max_length=255, null=True, verbose_name="Provenance" + ), + ), + ( + "collection", + models.ManyToManyField( + editable=False, to="apis_metainfo.collection" + ), + ), + ], + options={ + "abstract": False, + }, + bases=("apis_metainfo.rootobject", models.Model), + ), + migrations.CreateModel( + name="VersionInstance", + fields=[ + ( + "rootobject_ptr", + models.ForeignKey( + auto_created=True, + blank=True, + db_constraint=False, + null=True, + on_delete=django.db.models.deletion.DO_NOTHING, + parent_link=True, + related_name="+", + to="apis_metainfo.rootobject", + ), + ), + ( + "id", + models.IntegerField( + auto_created=True, blank=True, db_index=True, verbose_name="ID" + ), + ), + ("start_date", models.DateField(blank=True, editable=False, null=True)), + ( + "start_start_date", + models.DateField(blank=True, editable=False, null=True), + ), + ( + "start_end_date", + models.DateField(blank=True, editable=False, null=True), + ), + ("end_date", models.DateField(blank=True, editable=False, null=True)), + ( + "end_start_date", + models.DateField(blank=True, editable=False, null=True), + ), + ( + "end_end_date", + models.DateField(blank=True, editable=False, null=True), + ), + ( + "start_date_written", + models.CharField( + blank=True, max_length=255, null=True, verbose_name="Start" + ), + ), + ( + "end_date_written", + models.CharField( + blank=True, max_length=255, null=True, verbose_name="End" + ), + ), + ( + "version_tag", + models.CharField(blank=True, max_length=255, null=True), + ), + ("comments", models.TextField(blank=True, null=True)), + ( + "alternative_names", + models.TextField( + blank=True, null=True, verbose_name="Alternative names" + ), + ), + ( + "external_links", + models.TextField( + blank=True, null=True, verbose_name="External links" + ), + ), + ( + "review", + models.BooleanField( + default=False, + help_text="Should be set to True, if the data record holds up quality standards.", + ), + ), + ( + "notes", + models.TextField(blank=True, null=True, verbose_name="Notes"), + ), + ("published", models.BooleanField(default=False)), + ( + "name", + models.CharField( + blank=True, default="", max_length=255, verbose_name="Name" + ), + ), + ( + "set_num", + models.CharField( + blank=True, + choices=[ + ("Set 1", "Set 1"), + ("Set 2", "Set 2"), + ("Set 3", "Set 3"), + ("Set 4", "Set 4"), + ], + max_length=5, + null=True, + verbose_name="Set", + ), + ), + ("volume", models.CharField(blank=True, max_length=255, null=True)), + ( + "sb_text_number", + models.TextField( + blank=True, + null=True, + verbose_name="Number ascribed to item by Tibschol", + ), + ), + ( + "pp_kdsb", + models.CharField( + blank=True, + max_length=255, + null=True, + verbose_name="Page numbers in print", + ), + ), + ( + "num_folios", + models.CharField( + blank=True, + max_length=255, + null=True, + verbose_name="Number of folios", + ), + ), + ( + "signature_letter", + models.CharField( + blank=True, + max_length=255, + null=True, + verbose_name="Signature letter (category)", + ), + ), + ( + "signature_number", + models.CharField( + blank=True, + max_length=255, + null=True, + verbose_name="Signature number", + ), + ), + ( + "drepung_number", + models.CharField( + blank=True, + max_length=255, + null=True, + verbose_name="Drepung catalogue number", + ), + ), + ( + "provenance", + models.CharField( + blank=True, max_length=255, null=True, verbose_name="Provenance" + ), + ), + ("history_id", models.AutoField(primary_key=True, serialize=False)), + ("history_date", models.DateTimeField(db_index=True)), + ("history_change_reason", models.CharField(max_length=100, null=True)), + ( + "history_type", + models.CharField( + choices=[("+", "Created"), ("~", "Changed"), ("-", "Deleted")], + max_length=1, + ), + ), + ( + "history_user", + models.ForeignKey( + null=True, + on_delete=django.db.models.deletion.SET_NULL, + related_name="+", + to=settings.AUTH_USER_MODEL, + ), + ), + ( + "self_contenttype", + models.ForeignKey( + blank=True, + db_constraint=False, + editable=False, + null=True, + on_delete=django.db.models.deletion.DO_NOTHING, + related_name="+", + to="contenttypes.contenttype", + ), + ), + ], + options={ + "verbose_name": "Version", + "verbose_name_plural": "Versions", + "ordering": ("-history_date", "-history_id"), + "get_latest_by": ("history_date", "history_id"), + }, + bases=( + simple_history.models.HistoricalChanges, + models.Model, + apis_core.generic.abc.GenericModel, + ), + ), + migrations.CreateModel( + name="VersionInstance_collection", + fields=[ + ( + "id", + models.IntegerField( + auto_created=True, blank=True, db_index=True, verbose_name="ID" + ), + ), + ("m2m_history_id", models.AutoField(primary_key=True, serialize=False)), + ( + "collection", + models.ForeignKey( + blank=True, + db_constraint=False, + db_tablespace="", + null=True, + on_delete=django.db.models.deletion.DO_NOTHING, + related_name="+", + to="apis_metainfo.collection", + ), + ), + ( + "history", + models.ForeignKey( + db_constraint=False, + on_delete=django.db.models.deletion.DO_NOTHING, + to="apis_ontology.versioninstance", + ), + ), + ( + "instance", + models.ForeignKey( + blank=True, + db_constraint=False, + db_tablespace="", + null=True, + on_delete=django.db.models.deletion.DO_NOTHING, + related_name="+", + to="apis_ontology.instance", + ), + ), + ], + options={ + "verbose_name": "VersionInstance_collection", + }, + bases=(simple_history.models.HistoricalChanges, models.Model), + ), + ] diff --git a/apis_ontology/migrations/0006_instance_availability_instance_item_description_and_more.py b/apis_ontology/migrations/0006_instance_availability_instance_item_description_and_more.py new file mode 100644 index 0000000..d9d4cf2 --- /dev/null +++ b/apis_ontology/migrations/0006_instance_availability_instance_item_description_and_more.py @@ -0,0 +1,81 @@ +# Generated by Django 4.2.11 on 2024-04-22 06:41 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ("apis_ontology", "0005_instance_versioninstance_versioninstance_collection"), + ] + + operations = [ + migrations.AddField( + model_name="instance", + name="availability", + field=models.CharField( + blank=True, + choices=[ + ("lost", "lost"), + ("available", "available"), + ("non-accessible", "non-accessible"), + ], + max_length=15, + null=True, + verbose_name="Availability", + ), + ), + migrations.AddField( + model_name="instance", + name="item_description", + field=models.TextField( + blank=True, null=True, verbose_name="Item description" + ), + ), + migrations.AddField( + model_name="instance", + name="tibschol_ref", + field=models.TextField( + blank=True, null=True, verbose_name="Tibschol reference" + ), + ), + migrations.AddField( + model_name="instance", + name="zotero_ref", + field=models.TextField(blank=True, null=True, verbose_name="Zotero"), + ), + migrations.AddField( + model_name="versioninstance", + name="availability", + field=models.CharField( + blank=True, + choices=[ + ("lost", "lost"), + ("available", "available"), + ("non-accessible", "non-accessible"), + ], + max_length=15, + null=True, + verbose_name="Availability", + ), + ), + migrations.AddField( + model_name="versioninstance", + name="item_description", + field=models.TextField( + blank=True, null=True, verbose_name="Item description" + ), + ), + migrations.AddField( + model_name="versioninstance", + name="tibschol_ref", + field=models.TextField( + blank=True, null=True, verbose_name="Tibschol reference" + ), + ), + migrations.AddField( + model_name="versioninstance", + name="zotero_ref", + field=models.TextField(blank=True, null=True, verbose_name="Zotero"), + ), + ] diff --git a/apis_ontology/migrations/0007_alter_instance_options.py b/apis_ontology/migrations/0007_alter_instance_options.py new file mode 100644 index 0000000..340f3e7 --- /dev/null +++ b/apis_ontology/migrations/0007_alter_instance_options.py @@ -0,0 +1,20 @@ +# Generated by Django 4.2.11 on 2024-04-22 06:42 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ( + "apis_ontology", + "0006_instance_availability_instance_item_description_and_more", + ), + ] + + operations = [ + migrations.AlterModelOptions( + name="instance", + options={"verbose_name": "instance", "verbose_name_plural": "Instances"}, + ), + ] diff --git a/apis_ontology/models.py b/apis_ontology/models.py index e64be09..6a9dfd6 100644 --- a/apis_ontology/models.py +++ b/apis_ontology/models.py @@ -54,6 +54,30 @@ def uri(self): return uri +class Person( + VersionMixin, LegacyStuffMixin, LegacyDateMixin, TibScholEntityMixin, AbstractEntity +): + class_uri = "http://id.loc.gov/ontologies/bibframe/Person" + GENDERS = [ + ("male", "Male"), + ("female", "Female"), + ] + NATIONALITY = [("Indic", "Indic"), ("Tibetan", "Tibetan")] + + name = models.CharField(max_length=255, blank=True, default="", verbose_name="Name") + gender = models.CharField(max_length=6, choices=GENDERS, default="male") + nationality = models.CharField( + max_length=10, choices=NATIONALITY, blank=True, null=True + ) + + class Meta: + verbose_name = _("person") + verbose_name_plural = _("Persons") + + def __str__(self): + return f"{self.name}" + + class Place( E53_Place, VersionMixin, @@ -72,6 +96,113 @@ def __str__(self): return f"{self.label}" +class Work( + VersionMixin, LegacyStuffMixin, LegacyDateMixin, TibScholEntityMixin, AbstractEntity +): + class_uri = "http://id.loc.gov/ontologies/bibframe/Work" + LANGUAGES = [ + ("Sanskrit", "Sanskrit"), + ("Tibetan", "Tibetan"), + ("Tangut", "Tangut"), + ("Other", "Other"), + ] + subject = models.CharField( + max_length=255, + blank=True, + null=True, + verbose_name="subject", + ) # should be a controlled vocabulary field + + name = models.CharField(max_length=255, blank=True, default="", verbose_name="Name") + sde_dge_ref = models.CharField( + max_length=25, blank=True, null=True, verbose_name="Derge reference" + ) + original_language = models.CharField( + max_length=10, choices=LANGUAGES, blank=True, null=True + ) + isExtant = models.BooleanField(default=True, verbose_name="Is extant") + + class Meta: + verbose_name = _("work") + verbose_name_plural = _("Works") + + def __str__(self): + return f"{self.name}" + + +class Instance( + VersionMixin, LegacyStuffMixin, LegacyDateMixin, TibScholEntityMixin, AbstractEntity +): + class_uri = "http://id.loc.gov/ontologies/bibframe/Instance" + SETS = [ + ("Set 1", "Set 1"), + ("Set 2", "Set 2"), + ("Set 3", "Set 3"), + ("Set 4", "Set 4"), + ] + AVAILABILITY = [ + ("lost", "lost"), + ("available", "available"), + ("non-accessible", "non-accessible"), + ] + name = models.CharField(max_length=255, blank=True, default="", verbose_name="Name") + set_num = models.CharField( + max_length=5, choices=SETS, null=True, blank=True, verbose_name="Set" + ) + volume = models.CharField(max_length=255, blank=True, null=True) + sb_text_number = models.TextField( + blank=True, + null=True, + verbose_name="Number ascribed to item by Tibschol", + ) + pp_kdsb = models.CharField( + max_length=255, + blank=True, + null=True, + verbose_name="Page numbers in print", + ) + num_folios = models.CharField( + max_length=255, blank=True, null=True, verbose_name="Number of folios" + ) + + signature_letter = models.CharField( + max_length=255, + blank=True, + null=True, + verbose_name="Signature letter (category)", + ) + signature_number = models.CharField( + max_length=255, blank=True, null=True, verbose_name="Signature number" + ) + drepung_number = models.CharField( + max_length=255, blank=True, null=True, verbose_name="Drepung catalogue number" + ) + provenance = models.CharField( + max_length=255, blank=True, null=True, verbose_name="Provenance" + ) + zotero_ref = models.TextField(blank=True, null=True, verbose_name="Zotero") + tibschol_ref = models.TextField( + blank=True, null=True, verbose_name="Tibschol reference" + ) + availability = models.CharField( + max_length=15, + choices=AVAILABILITY, + blank=True, + null=True, + verbose_name="Availability", + ) + item_description = models.TextField( + blank=True, null=True, verbose_name="Item description" + ) + + class Meta: + verbose_name = _("instance") + verbose_name_plural = _("Instances") + + def __str__(self): + return f"{self.name}" + + class ZoteroEntry(GenericModel, models.Model): zoteroId = models.CharField(max_length=255, verbose_name="Zotero ID") shortTitle = models.TextField(blank=True, null=True, verbose_name="Short title")