Skip to content

Commit

Permalink
add reference model
Browse files Browse the repository at this point in the history
  • Loading branch information
lukavdplas committed Feb 9, 2024
1 parent 4307416 commit fff75fd
Show file tree
Hide file tree
Showing 2 changed files with 89 additions and 0 deletions.
31 changes: 31 additions & 0 deletions backend/source/migrations/0002_reference.py
Original file line number Diff line number Diff line change
@@ -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')],
},
),
]
58 changes: 58 additions & 0 deletions backend/source/models.py
Original file line number Diff line number Diff line change
@@ -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,
Expand All @@ -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"])]

0 comments on commit fff75fd

Please sign in to comment.