fix(words): Relations-Setup automatisch beim ersten Word-Save
words_pictures M2M-Relationen werden idempotent beim POST eingerichtet – kein manueller Setup-Call nötig. Co-Authored-By: Claude Sonnet 4.6 <noreply@anthropic.com>
This commit is contained in:
29
app.py
29
app.py
@@ -149,7 +149,36 @@ def directus_picture_words(pic_id):
|
|||||||
else: # POST
|
else: # POST
|
||||||
body = request.get_json(force=True, silent=True) or {}
|
body = request.get_json(force=True, silent=True) or {}
|
||||||
words = body.get("words", [])
|
words = body.get("words", [])
|
||||||
|
|
||||||
|
# Junction + Relationen idempotent einrichten
|
||||||
_ensure_junction("words_pictures", "words_id", "pictures_id", token)
|
_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
|
saved = 0
|
||||||
for entry in words:
|
for entry in words:
|
||||||
title_de = (entry.get("title_de") or "").strip()
|
title_de = (entry.get("title_de") or "").strip()
|
||||||
|
|||||||
Reference in New Issue
Block a user