From e6a07a5125888cf85302e0b5bb29092726607a78 Mon Sep 17 00:00:00 2001
From: "J. R. Schmid" <schmidj@saw-leipzig.de>
Date: Mon, 3 May 2021 12:46:53 +0200
Subject: [PATCH] When creating the directory for _a_ model, also create the
 path leading up to the model_s_ directory.

---
 app/apps/core/tasks.py | 4 ++--
 1 file changed, 2 insertions(+), 2 deletions(-)

diff --git a/app/apps/core/tasks.py b/app/apps/core/tasks.py
index e0b37852..7d5732be 100644
--- a/app/apps/core/tasks.py
+++ b/app/apps/core/tasks.py
@@ -3,6 +3,7 @@ import json
 import logging
 import numpy as np
 import os.path
+import pathlib
 import shutil
 from itertools import groupby
 
@@ -352,8 +353,7 @@ def train_(qs, document, transcription, model=None, user=None):
         filename = slugify(model.name) + '.mlmodel'
         upload_to = model.file.field.upload_to(model, filename)
         fulldir = os.path.join(settings.MEDIA_ROOT, os.path.split(upload_to)[0], '')
-        if not os.path.exists(fulldir):
-            os.mkdir(fulldir)
+        pathlib.Path(fulldir).mkdir(parents=True, exist_ok=True)
         modelpath = os.path.join(fulldir, filename)
         model.file = upload_to
         model.save()
-- 
GitLab