From 05904584c707744e9789bc9beb661407379745e6 Mon Sep 17 00:00:00 2001 From: Gytha Ogg Date: Mon, 22 Apr 2024 08:42:54 +0200 Subject: [PATCH] Model Instance --- ...sioninstance_versioninstance_collection.py | 436 ++++++++++++++++++ ...lity_instance_item_description_and_more.py | 81 ++++ .../migrations/0007_alter_instance_options.py | 20 + apis_ontology/models.py | 73 +++ 4 files changed, 610 insertions(+) create mode 100644 apis_ontology/migrations/0005_instance_versioninstance_versioninstance_collection.py create mode 100644 apis_ontology/migrations/0006_instance_availability_instance_item_description_and_more.py create mode 100644 apis_ontology/migrations/0007_alter_instance_options.py 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 0883a77..6a9dfd6 100644 --- a/apis_ontology/models.py +++ b/apis_ontology/models.py @@ -130,6 +130,79 @@ 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")