diff --git a/app.py b/app.py index 41fa35d..b6708d1 100644 --- a/app.py +++ b/app.py @@ -1262,6 +1262,24 @@ def delete_word_item(w_id: str): return jsonify({"error": "Delete failed"}), status +@app.route("/api/fix-distractor-field", methods=["POST"]) +def fix_distractor_field(): + """Setzt special=m2m auf questions.distractor_words (einmalig).""" + token = request.headers.get("Authorization", "") + # Directus erfordert den vollen Payload beim Patchen von special + payload = { + "meta": { + "special": ["m2m"], + "interface": "list-m2m", + "options": {"template": "{{words_id.title_de}}"}, + "hidden": False, + "note": "Ablenker-Wörter (thematisch passend, aber nicht die Antwort)", + } + } + data, status = _directus("PATCH", "/fields/questions/distractor_words", token, payload) + return jsonify({"ok": status in (200, 201), "status": status, "data": data}) + + @app.route("/api/setup-schema", methods=["POST"]) def setup_directus_schema(): """ diff --git a/frontend/src/pages/GenerateIt.tsx b/frontend/src/pages/GenerateIt.tsx index 946608a..4a09e5b 100644 --- a/frontend/src/pages/GenerateIt.tsx +++ b/frontend/src/pages/GenerateIt.tsx @@ -323,10 +323,14 @@ export default function GenerateIt() { title="Directus-Schema einmalig konfigurieren (M2M-Relationen)" onClick={async () => { if (!token) return - const res = await fetch('/api/setup-schema', { method: 'POST', headers: { Authorization: `Bearer ${token}` } }) - const d = await res.json() - alert(`Setup: ${d.total} Schritte, ${d.failed} Fehler.\nSiehe Konsole für Details.`) - console.log('[setup-schema]', d) + const h = { Authorization: `Bearer ${token}` } + const [r1, r2] = await Promise.all([ + fetch('/api/setup-schema', { method: 'POST', headers: h }), + fetch('/api/fix-distractor-field', { method: 'POST', headers: h }), + ]) + const [d1, d2] = await Promise.all([r1.json(), r2.json()]) + alert(`Setup: ${d1.total} Schritte, ${d1.failed} Fehler\nDistractor-Fix: ${d2.ok ? 'OK' : 'Fehler'}`) + console.log('[setup-schema]', d1, '[fix-distractor]', d2) }} > ⚙ Schema