41 lines
1.3 KiB
Python
41 lines
1.3 KiB
Python
from django.db import models
|
|
from django.conf import settings
|
|
|
|
import ox
|
|
|
|
class Event(models.Model):
|
|
|
|
class Meta:
|
|
ordering = ('position', 'date')
|
|
|
|
created = models.DateTimeField(auto_now_add=True)
|
|
modified = models.DateTimeField(auto_now=True)
|
|
|
|
slug = models.SlugField(blank=True, unique=True)
|
|
|
|
position = models.IntegerField(default=0)
|
|
title = models.TextField(blank=True)
|
|
type = models.CharField(blank=True, default='', max_length=1024)
|
|
date = models.CharField(blank=True, null=True, max_length=1024)
|
|
body = models.TextField(blank=True, null=True)
|
|
media = models.TextField(blank=True, null=True)
|
|
media_caption = models.TextField(blank=True, null=True, default='')
|
|
|
|
|
|
data = models.JSONField(default=dict, blank=True, editable=False)
|
|
|
|
def __str__(self):
|
|
return '%s (%s)' % (ox.strip_tags(self.title), self.slug)
|
|
|
|
def get_absolute_url(self):
|
|
return '/' + settings.URL_PREFIX + '#' + self.slug
|
|
|
|
def media_html(self):
|
|
html = ''
|
|
if self.media and self.media.split('.')[-1] in ('jpg', 'png', 'gif'):
|
|
html += '<img src="%s">' % self.media
|
|
else:
|
|
html += '<iframe src="%s"></iframe>' % self.media
|
|
if self.media_caption:
|
|
html = '<figure>%s<figcaption>%s</figcaption></figure>' % (html, self.media_caption)
|
|
return html
|