Support many-to-many with tags
This commit is contained in:
parent
56abc03f31
commit
779ee06149
4 changed files with 26 additions and 2 deletions
|
@ -1,5 +1,7 @@
|
||||||
---
|
---
|
||||||
title: Test
|
title: Test
|
||||||
|
tags:
|
||||||
|
- tag-1
|
||||||
---
|
---
|
||||||
|
|
||||||
# Heading
|
# Heading
|
||||||
|
|
2
content/core.tag/tags.yml
Normal file
2
content/core.tag/tags.yml
Normal file
|
@ -0,0 +1,2 @@
|
||||||
|
- slug: tag-1
|
||||||
|
- slug: tag-2
|
|
@ -1,4 +1,4 @@
|
||||||
django
|
django
|
||||||
git+https://github.com/andrewgodwin/yamdl
|
git+https://github.com/andrewgodwin/yamdl@8d34d7397f3564a550042e81ea79cca7d2f3777e
|
||||||
gunicorn
|
gunicorn
|
||||||
markdown
|
markdown
|
||||||
|
|
|
@ -1,9 +1,29 @@
|
||||||
from django.db import models
|
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):
|
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, default=None, null=True)
|
|
||||||
|
|
||||||
content = models.TextField()
|
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
|
||||||
|
|
Loading…
Reference in a new issue