I have model with FileField, which contains audio file:
class Word(models.Model):
theme = models.ManyToManyField(Theme, related_name='words')
name = models.CharField(max_length=200, null=True, blank=True)
sound = models.FileField(upload_to='sounds/', blank=True)
I need show audio player on admin panel for this model.
For example, for ImageField I did this:
from django.utils.html import mark_safeand add property to model code
@property
def icon_preview(self):
if self.icon:
return mark_safe(f'<img src="{self.icon.url}" width="100" height="100" />')
return ""
- in
admin.pyadd code:
list_display = ('id', 'name', 'icon', 'icon_preview')
readonly_fields = ('icon_preview',)
def icon_preview(self, item):
return item.icon_preview
icon_preview.short_description = 'icon preview'
icon_preview.allow_tags = True
And I need to do something similar for the sound