diff --git a/app.py b/app.py index fd46837..a3a4979 100644 --- a/app.py +++ b/app.py @@ -149,7 +149,36 @@ def directus_picture_words(pic_id): else: # POST body = request.get_json(force=True, silent=True) or {} words = body.get("words", []) + + # Junction + Relationen idempotent einrichten _ensure_junction("words_pictures", "words_id", "pictures_id", token) + _directus("PATCH", "/fields/pictures/linked_words", token, { + "type": "alias", + "meta": {"special": ["m2m"], "interface": "list-m2m", + "options": {"template": "{{words_id.title_de}}"}}, + }) + _directus("PATCH", "/fields/words/linked_pictures", token, { + "type": "alias", + "meta": {"special": ["m2m"], "interface": "list-m2m", + "options": {"template": "{{pictures_id.media}}"}}, + }) + _directus("POST", "/relations", token, { + "collection": "words_pictures", "field": "words_id", + "related_collection": "words", + "schema": {"on_delete": "CASCADE"}, + "meta": {"junction_field": "pictures_id", + "one_field": "linked_pictures", + "one_deselect_action": "nullify"}, + }) + _directus("POST", "/relations", token, { + "collection": "words_pictures", "field": "pictures_id", + "related_collection": "pictures", + "schema": {"on_delete": "CASCADE"}, + "meta": {"junction_field": "words_id", + "one_field": "linked_words", + "one_deselect_action": "nullify"}, + }) + saved = 0 for entry in words: title_de = (entry.get("title_de") or "").strip()