njpma/app/text/models.py
2021-10-11 13:55:45 +01:00

56 lines
1.5 KiB
Python

import logging
import json
from django.conf import settings
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(blank=True, unique=True)
public = models.BooleanField(default=False)
title = models.TextField(blank=True)
body = models.TextField(blank=True)
data = models.JSONField(default=dict, blank=True)
def __str__(self):
return '%s (%s)' % (self.title, self.slug)
def get_absolute_url(self):
if self.slug:
return '/' + settings.URL_PREFIX + '' + self.slug
else:
return '/' + settings.URL_PREFIX[:-1]
class Text(models.Model):
created = models.DateTimeField(auto_now_add=True)
modified = models.DateTimeField(auto_now=True)
slug = models.SlugField()
public = models.BooleanField(default=False)
position = models.IntegerField(default=0)
title = models.TextField()
byline = models.TextField(default="", blank=True)
body = models.TextField(default="", blank=True)
data = models.JSONField(default=dict)
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)