Skip to content

Commit

Permalink
Remove reference model
Browse files Browse the repository at this point in the history
  • Loading branch information
XanderVertegaal committed Mar 24, 2024
1 parent b3e5a55 commit 8ad1b06
Show file tree
Hide file tree
Showing 7 changed files with 17 additions and 107 deletions.
31 changes: 1 addition & 30 deletions backend/core/management/commands/create_dev_dataset.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@
from django.conf import settings
from django.core.management.base import CommandError, BaseCommand
from faker import Faker
from source.models import Reference, Source
from source.models import Source

from case_study.models import CaseStudy
from event.models import (
Expand Down Expand Up @@ -137,7 +137,6 @@ def handle(self, *args, **options):
fake, options, total=50, model=EpistolaryEventSelfTrigger
)
self._create_sources(fake, options, total=50, model=Source)
self._create_references(fake, options, total=250, model=Reference)

print("-" * 80)
print("Development dataset created successfully.")
Expand Down Expand Up @@ -352,31 +351,3 @@ def _create_epistolary_event_self_trigger(self, fake, options, total, model):
def _create_sources(self, fake, options, total, model):
unique_name = get_unique_name(source_names, Source)
Source.objects.create(name=unique_name, bibliographical_info=fake.text())

@track_progress
def _create_references(self, fake, options, total, model):
random_content_type = (
ContentType.objects.exclude(
app_label__in=["admin", "auth", "contenttypes", "sessions", "source"]
)
.order_by("?")
.first()
)

random_objects = random_content_type.model_class().objects.all()

if not random_objects.exists():
return

random_object_id = random_objects.order_by("?").first().id

random_source = Source.objects.order_by("?").first()

Reference.objects.create(
content_type=random_content_type,
object_id=random_object_id,
source=random_source,
location=f"chapter {random.randint(1, 10)}, page {random.randint(1, 100)}",
terminology=fake.words(nb=3, unique=True),
mention=random.choice(["direct", "implied"]),
)
2 changes: 0 additions & 2 deletions backend/event/admin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from django.contrib import admin
from source.admin import ReferenceInlineAdmin
from . import models


Expand Down Expand Up @@ -55,7 +54,6 @@ class LetterActionAdmin(admin.ModelAdmin):
LetterActionGiftsAdmin,
EventDateAdmin,
RoleAdmin,
ReferenceInlineAdmin,
]
exclude = ["letters"]

Expand Down
2 changes: 0 additions & 2 deletions backend/letter/admin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from django.contrib import admin
from source.admin import ReferenceInlineAdmin
from . import models


Expand Down Expand Up @@ -38,7 +37,6 @@ class LetterAdmin(admin.ModelAdmin):
LetterMaterialAdmin,
LetterSenderAdmin,
LetterAddresseesAdmin,
ReferenceInlineAdmin,
]


Expand Down
11 changes: 0 additions & 11 deletions backend/source/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,3 @@
@admin.register(models.Source)
class SourceAdmin(admin.ModelAdmin):
fields = ["name", "bibliographical_info"]


class ReferenceInlineAdmin(GenericStackedInline):
model = models.Reference
fields = [
"source",
"location",
"terminology",
"mention",
]
extra = 0
16 changes: 16 additions & 0 deletions backend/source/migrations/0004_delete_reference.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# Generated by Django 4.2.7 on 2024-03-24 09:08

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("source", "0003_alter_reference_location_alter_reference_mention_and_more"),
]

operations = [
migrations.DeleteModel(
name="Reference",
),
]
60 changes: 0 additions & 60 deletions backend/source/models.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,4 @@
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):
Expand All @@ -22,60 +19,3 @@ 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=list,
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 information presented in the text?",
)

def __str__(self):
object = f"{self.content_object} ({self.content_type.model})"
source = f"{self.source}"
loc = f" ({self.location})" if self.location else ""
return f"reference to {object} in {source}{loc}"

class Meta:
indexes = [models.Index(fields=["content_type", "object_id"])]
2 changes: 0 additions & 2 deletions backend/space/admin.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
from django.contrib import admin
from source.admin import ReferenceInlineAdmin
from . import models


Expand Down Expand Up @@ -72,5 +71,4 @@ class SpaceDescriptionAdmin(admin.ModelAdmin):
GeographicalRegionFieldInlineAdmin,
StructureFieldInlineAdmin,
LandscapeFeatureInlineAdmin,
ReferenceInlineAdmin,
]

0 comments on commit 8ad1b06

Please sign in to comment.