render media
This commit is contained in:
parent
c425753f11
commit
8a8abd33ff
2 changed files with 13 additions and 1 deletions
|
@ -21,6 +21,7 @@ class Event(models.Model):
|
||||||
media = models.TextField(blank=True, null=True)
|
media = models.TextField(blank=True, null=True)
|
||||||
media_caption = models.TextField(blank=True, null=True, default='')
|
media_caption = models.TextField(blank=True, null=True, default='')
|
||||||
|
|
||||||
|
|
||||||
data = models.JSONField(default=dict, blank=True, editable=False)
|
data = models.JSONField(default=dict, blank=True, editable=False)
|
||||||
|
|
||||||
def __str__(self):
|
def __str__(self):
|
||||||
|
@ -28,3 +29,13 @@ class Event(models.Model):
|
||||||
|
|
||||||
def get_absolute_url(self):
|
def get_absolute_url(self):
|
||||||
return '/' + settings.URL_PREFIX + '#' + self.slug
|
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
|
||||||
|
|
|
@ -13,7 +13,8 @@
|
||||||
{% if event.media %}
|
{% if event.media %}
|
||||||
<div class="side-by-side">
|
<div class="side-by-side">
|
||||||
<div class="media">
|
<div class="media">
|
||||||
{{ event.media | safe }}
|
|
||||||
|
{{ event.media_html | safe }}
|
||||||
</div>
|
</div>
|
||||||
<div class="text">
|
<div class="text">
|
||||||
{{ event.body | safe }}
|
{{ event.body | safe }}
|
||||||
|
|
Loading…
Reference in a new issue