phantasma/app/text/models.py
2021-10-11 13:29:23 +01:00

57 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)
public = models.BooleanField(default=False)
title = models.TextField(blank=True)
#teaser = 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)
title = models.TextField()
teaser = 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)