29 lines
652 B
Python
29 lines
652 B
Python
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)
|
|
|
|
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
|