Skip to content

Commit

Permalink
feat(rdfimport): add get_or_create method to models
Browse files Browse the repository at this point in the history
Add `get_or_create_uri` methods to models to create new
objects from RDF data if the URIs in question don't already
exist.
  • Loading branch information
koeaw committed May 28, 2024
1 parent 6566dac commit 84d2352
Showing 1 changed file with 9 additions and 0 deletions.
9 changes: 9 additions & 0 deletions apis_ontology/models.py
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
from apis_core.apis_entities.models import AbstractEntity
from apis_core.apis_relations.models import Property
from apis_core.utils.helpers import create_object_from_uri
from dateparser import parse
from django.conf import settings
from django.contrib.contenttypes.models import ContentType
Expand Down Expand Up @@ -766,6 +767,10 @@ class Person(PersonNameMixin, DescriptionMixin, StatusMixin, AbstractEntity):
class Meta:
verbose_name_plural = _("personen")

@classmethod
def get_or_create_uri(cls, uri):
return create_object_from_uri(uri, cls) or cls.objects.get(pk=uri)


class Organisation(
GenericNameMixin,
Expand Down Expand Up @@ -915,6 +920,10 @@ class Meta:
verbose_name = _("ort")
verbose_name_plural = _("orte")

@classmethod
def get_or_create_uri(cls, uri):
return create_object_from_uri(uri, cls) or cls.objects.get(pk=uri)


class ResearchPerspective(
GenericNameMixin,
Expand Down

0 comments on commit 84d2352

Please sign in to comment.