1
Fork 0

Fix slug for data file

This commit is contained in:
Jake Howard 2023-12-12 18:22:37 +00:00
parent 67dfd04bbb
commit 58fda689bf
Signed by: jake
GPG key ID: 57AFB45680EDD477
3 changed files with 6 additions and 2 deletions

View file

@ -1,2 +1,4 @@
- title: Foo - title: Foo
content: bar content: bar
- title: Bar
content: foo

View file

@ -4,6 +4,6 @@ class Page(models.Model):
__yamdl__ = True __yamdl__ = True
title = models.CharField(max_length=255) 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() content = models.TextField()

View file

@ -2,5 +2,7 @@ from yamdl.loader import ModelLoader
class CustomYamdlLoader(ModelLoader): class CustomYamdlLoader(ModelLoader):
def load_fixture(self, model_class, data, file_path): 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) super().load_fixture(model_class, data, file_path)