1
Fork 0
yamdl-playground/yamdl_playground/core/models.py

30 lines
652 B
Python
Raw Normal View History

2023-12-06 23:30:01 +00:00
from django.db import models
2024-01-10 21:59:54 +00:00
class Tag(models.Model):
__yamdl__ = True
slug = models.SlugField(max_length=128, primary_key=True)
content = models.TextField()
2023-12-06 23:30:01 +00:00
class Page(models.Model):
__yamdl__ = True
title = models.CharField(max_length=255)
content = models.TextField()
2024-01-10 21:59:54 +00:00
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