From 58fda689bfc834fc270d4521bb73dfa95f0aebb3 Mon Sep 17 00:00:00 2001 From: Jake Howard Date: Tue, 12 Dec 2023 18:22:37 +0000 Subject: [PATCH] Fix slug for data file --- content/core.page/test.yaml | 2 ++ yamdl_playground/core/models.py | 2 +- yamdl_playground/core/utils.py | 4 +++- 3 files changed, 6 insertions(+), 2 deletions(-) diff --git a/content/core.page/test.yaml b/content/core.page/test.yaml index 90260bb..c7952a9 100644 --- a/content/core.page/test.yaml +++ b/content/core.page/test.yaml @@ -1,2 +1,4 @@ - title: Foo content: bar +- title: Bar + content: foo diff --git a/yamdl_playground/core/models.py b/yamdl_playground/core/models.py index 80807c1..3d0314d 100644 --- a/yamdl_playground/core/models.py +++ b/yamdl_playground/core/models.py @@ -4,6 +4,6 @@ class Page(models.Model): __yamdl__ = True title = models.CharField(max_length=255) - slug = models.CharField(max_length=128, unique=True, db_index=True) + slug = models.CharField(max_length=128, unique=True, db_index=True, default=None, null=True) content = models.TextField() diff --git a/yamdl_playground/core/utils.py b/yamdl_playground/core/utils.py index 9c8399d..7395799 100644 --- a/yamdl_playground/core/utils.py +++ b/yamdl_playground/core/utils.py @@ -2,5 +2,7 @@ from yamdl.loader import ModelLoader class CustomYamdlLoader(ModelLoader): def load_fixture(self, model_class, data, file_path): - data["slug"] = file_path.stem + if file_path.suffix not in self.EXT_YAML: + data["slug"] = file_path.stem + super().load_fixture(model_class, data, file_path)