Add field for media alt

This commit is contained in:
MatthiasSaihttam 2021-05-01 16:02:52 -04:00
parent f7ab61cbee
commit 980f94cd7f
3 changed files with 20 additions and 1 deletions

View File

@ -0,0 +1,18 @@
# Generated by Django 3.2 on 2021-05-01 20:01
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('main', '0004_thought_media'),
]
operations = [
migrations.AddField(
model_name='thought',
name='media_alt',
field=models.TextField(blank=True),
),
]

View File

@ -11,6 +11,7 @@ class Thought(models.Model):
posted = models.DateTimeField(auto_now_add=True)
timezone_offset = models.IntegerField() # The number of minutes behind UTC we were when this was posted
media = models.FileField(upload_to="", blank=True) # A single image, video, or sound clip per post
media_alt = models.TextField(blank=True) # An optional transcription of the Thought's media
def get_media_type(self):
if not self.media:

View File

@ -19,7 +19,7 @@
<span class="extended-text text">{{thought.extended_text}}</span>
{% with file_type=thought.get_media_type %}
{% if file_type == "png" or file_type == "jpeg" %}
<img src="{{ thought.media.url }}" class="extended-media">
<img src="{{ thought.media.url }}" class="extended-media" alt="{{ thought.media_alt }}">
{% elif file_type == "m4a" or file_type == "mp3" or file_type == "aac" %}
<audio controls src="{{ thought.media.url }}" class="extended-media"></audio>
{% elif file_type == "mov" or file_type == "mp4" %}