diff --git a/backend/source/migrations/0002_reference.py b/backend/source/migrations/0002_reference.py new file mode 100644 index 00000000..b388508a --- /dev/null +++ b/backend/source/migrations/0002_reference.py @@ -0,0 +1,31 @@ +# Generated by Django 4.2.7 on 2024-02-09 13:18 + +import django.contrib.postgres.fields +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('contenttypes', '0002_remove_content_type_name'), + ('source', '0001_initial'), + ] + + operations = [ + migrations.CreateModel( + name='Reference', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('object_id', models.PositiveIntegerField()), + ('location', models.CharField(blank=True, help_text='specific location of the reference in the source text', max_length=200)), + ('terminology', django.contrib.postgres.fields.ArrayField(base_field=models.CharField(max_length=200), blank=True, default=[], help_text='terminology used in the source text to describe this entity', size=5)), + ('mention', models.CharField(blank=True, choices=[('direct', 'directly mentioned'), ('implied', 'implied')], help_text='how is this entity presented in the text?', max_length=32)), + ('content_type', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='contenttypes.contenttype')), + ('source', models.ForeignKey(help_text='the source text in which this references occurs', on_delete=django.db.models.deletion.CASCADE, to='source.source')), + ], + options={ + 'indexes': [models.Index(fields=['content_type', 'object_id'], name='source_refe_content_816b0e_idx')], + }, + ), + ] diff --git a/backend/source/models.py b/backend/source/models.py index 0c543179..a1ea67e3 100644 --- a/backend/source/models.py +++ b/backend/source/models.py @@ -1,7 +1,14 @@ from django.db import models +from django.contrib.postgres.fields import ArrayField +from django.contrib.contenttypes.fields import GenericForeignKey +from django.contrib.contenttypes.models import ContentType class Source(models.Model): + """ + A Source is a text of any kind. + """ + name = models.CharField( max_length=200, blank=False, @@ -15,3 +22,54 @@ class Source(models.Model): def __str__(self): return self.name + +class Reference(models.Model): + """ + References link information to sources. + + A Reference describes where and how a source refers to the information presented + in the database object. + """ + + # reference to the object + # c.f. https://docs.djangoproject.com/en/4.2/ref/contrib/contenttypes/#generic-relations + + content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE) + object_id = models.PositiveIntegerField() + content_object = GenericForeignKey("content_type", "object_id") + + # reference to a source + + source = models.ForeignKey( + to=Source, + on_delete=models.CASCADE, + help_text="the source text in which this references occurs", + ) + + # description of the reference + + location = models.CharField( + max_length=200, + blank=True, + help_text="specific location of the reference in the source text", + ) + + terminology = ArrayField( + models.CharField( + max_length=200, + ), + default=[], + blank=True, + size=5, + help_text="terminology used in the source text to describe this entity", + ) + + mention = models.CharField( + max_length=32, + blank=True, + choices=[("direct", "directly mentioned"), ("implied", "implied")], + help_text="how is this entity presented in the text?", + ) + + class Meta: + indexes = [models.Index(fields=["content_type", "object_id"])]