Skip to content
This repository has been archived by the owner on Mar 14, 2024. It is now read-only.

Commit

Permalink
feat: replace construct_properties with importproperties
Browse files Browse the repository at this point in the history
importproperties is a custom management script that reads the properties
from a json file and (re)creates them.
  • Loading branch information
b1rger committed Nov 9, 2023
1 parent ce72e59 commit b978989
Show file tree
Hide file tree
Showing 3 changed files with 550 additions and 420 deletions.
28 changes: 28 additions & 0 deletions apis_ontology/management/commands/importproperties.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
import json
from pathlib import Path

from django.core.management.base import BaseCommand
from apis_core.apis_relations.models import Property
from django.contrib.contenttypes.models import ContentType


class Command(BaseCommand):
help = "Import properties from data/properties.json"

def handle(self, *args, **options):
base_path = Path(__file__).resolve().parent.parent.parent.parent
properties_json = base_path / "data/properties.json"
data = json.loads(properties_json.read_text())

for p in data:
prop, _ = Property.objects.get_or_create(pk=p["id"])
prop.name = p["name"]
prop.name_reverse = p["name_reverse"]
prop.save()
prop.obj_class.clear()
for obj in p["obj"]:
prop.obj_class.add(ContentType.objects.get(model=obj))
prop.subj_class.clear()
for subj in p["subj"]:
prop.subj_class.add(ContentType.objects.get(model=subj))
print(prop)
Loading

0 comments on commit b978989

Please sign in to comment.