1
Fork 0

Support many-to-many with tags

This commit is contained in:
Jake Howard 2024-01-10 21:59:54 +00:00
parent 56abc03f31
commit 779ee06149
Signed by: jake
GPG key ID: 57AFB45680EDD477
4 changed files with 26 additions and 2 deletions

View file

@ -1,5 +1,7 @@
---
title: Test
tags:
- tag-1
---
# Heading

View file

@ -0,0 +1,2 @@
- slug: tag-1
- slug: tag-2

View file

@ -1,4 +1,4 @@
django
git+https://github.com/andrewgodwin/yamdl
git+https://github.com/andrewgodwin/yamdl@8d34d7397f3564a550042e81ea79cca7d2f3777e
gunicorn
markdown

View file

@ -1,9 +1,29 @@
from django.db import models
class Tag(models.Model):
__yamdl__ = True
slug = models.SlugField(max_length=128, primary_key=True)
content = models.TextField()
class Page(models.Model):
__yamdl__ = True
title = models.CharField(max_length=255)
slug = models.CharField(max_length=128, unique=True, db_index=True, default=None, null=True)
content = models.TextField()
slug = models.CharField(max_length=128, unique=True, db_index=True, default=None, null=True)
tags = models.ManyToManyField(Tag)
@classmethod
def from_yaml(cls, **data):
tags = data.pop("tags", None)
instance = cls.objects.create(**data)
if tags:
instance.tags.set(tags)
return instance