Skip to content

Commit

Permalink
fix: implement source connection
Browse files Browse the repository at this point in the history
  • Loading branch information
b1rger committed Oct 3, 2023
1 parent f3d6b3f commit 1c8808a
Show file tree
Hide file tree
Showing 3 changed files with 42 additions and 6 deletions.
14 changes: 8 additions & 6 deletions apis_ontology/management/commands/import.py
Original file line number Diff line number Diff line change
Expand Up @@ -192,12 +192,14 @@ def import_entities():
for profession in professionlist:
newentity.profession.add(profession)
newentity.save()
if "source" in result and "id" in result["source"]:
try:
source = Source.objects.get(pk=result["source"]["id"])
# set source target to entity
except Source.DoesNotExist:
pass
if result["source"] is not None:
if "id" in result["source"]:
try:
source = Source.objects.get(pk=result["source"]["id"])
source.content_object = newentity
# set source target to entity
except Source.DoesNotExist:
print(f"Source does not exist: {result['source']['id']}")


def import_relations():
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Generated by Django 4.1.11 on 2023-10-03 07:24

from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
('contenttypes', '0002_remove_content_type_name'),
('apis_ontology', '0005_source'),
]

operations = [
migrations.AddField(
model_name='source',
name='content_type',
field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to='contenttypes.contenttype'),
preserve_default=False,
),
migrations.AddField(
model_name='source',
name='object_id',
field=models.PositiveIntegerField(default=1),
preserve_default=False,
),
]
7 changes: 7 additions & 0 deletions apis_ontology/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
import reversion
from django.db import models
from django.contrib.contenttypes.fields import GenericForeignKey
from django.contrib.contenttypes.models import ContentType

from apis_core.apis_entities.models import AbstractEntity
from apis_core.core.models import LegacyDateMixin
from apis_core.utils import DateParser
Expand All @@ -24,6 +27,10 @@ class Source(models.Model):
author = models.CharField(max_length=255, blank=True)
orig_id = models.PositiveIntegerField(blank=True, null=True)

content_type = models.ForeignKey(ContentType, on_delete=models.CASCADE)
object_id = models.PositiveIntegerField()
content_object = GenericForeignKey('content_type', 'object_id')

def __str__(self):
if self.author and self.orig_filename:
return f"{self.orig_filename}, stored by {self.author}"
Expand Down

0 comments on commit 1c8808a

Please sign in to comment.