njpma/app/text/models.py

48 lines
1.2 KiB
Python
Raw Normal View History

2021-09-28 13:10:22 +00:00
import logging
2021-10-10 15:06:43 +00:00
import json
2021-09-28 13:10:22 +00:00
2021-10-10 15:06:43 +00:00
from django.conf import settings
2021-09-28 13:10:22 +00:00
from django.contrib.auth import get_user_model
from django.db import models
logger = logging.getLogger(__name__)
User = get_user_model()
class Page(models.Model):
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)
slug = models.SlugField()
public = models.BooleanField(default=False)
data = models.JSONField(default=dict)
title = models.TextField()
teaser = models.TextField()
body = models.TextField()
2021-10-10 15:06:43 +00:00
class Text(models.Model):
2021-09-28 13:10:22 +00:00
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)
slug = models.SlugField()
public = models.BooleanField(default=False)
2021-10-10 15:06:43 +00:00
title = models.TextField()
teaser = models.TextField(default="", blank=True)
body = models.TextField(default="", blank=True)
2021-09-28 13:10:22 +00:00
data = models.JSONField(default=dict)
2021-10-10 15:06:43 +00:00
def __str__(self):
return self.title
def get_absolute_url(self):
return '/' + settings.URL_PREFIX + 'assemblies/' + self.slug
def json(self):
data = {}
data['title'] = self.title
data.update(self.data)
return json.dumps(data)