Date:Mar 28, 2017
Keywords:django, python, audiofield, audio, wav, mp3, sox

Django-audiofield is an application written in Python, using the Django Framework.

The license is MIT.


Django-audiofield is a Django application which allows audio file upload and conversion to mp3, wav and ogg format. It also makes it easy to play the audio files into your django application, for this we integrated a HTML5 and Flash audio player ‘SoundManager2’

The goal of this project is to quickly manage audio files into your django project and make it easy for admins and users to listen to them.

_images/django-admin-audiofield.png _images/django-admin-audiofield-upload.png

More information about Soundmanager2 :


Add the following lines in your file:

from django.conf import settings
from audiofield.fields import AudioField
import os.path

# Add the audio field to your model
audio_file = AudioField(upload_to='your/upload/dir', blank=True,
                        ext_whitelist=(".mp3", ".wav", ".ogg"),
                        help_text=("Allowed type - .mp3, .wav, .ogg"))

# Add this method to your model
def audio_file_player(self):
    """audio player tag for admin"""
    if self.audio_file:
        file_url = settings.MEDIA_URL + str(self.audio_file)
        player_string = '<ul class="playlist"><li style="width:250px;">\
        <a href="%s">%s</a></li></ul>' % (file_url, os.path.basename(
        return player_string
audio_file_player.allow_tags = True
audio_file_player.short_description = _('Audio file player')

Add the following lines in your

from your_app.models import your_model_name

# add 'audio_file_player' tag to your admin view
list_display = (..., 'audio_file_player', ...)
actions = ['custom_delete_selected']

def custom_delete_selected(self, request, queryset):
    #custom delete code
    n = queryset.count()
    for i in queryset:
        if i.audio_file:
            if os.path.exists(i.audio_file.path):
    self.message_user(request, _("Successfully deleted %d audio files.") % n)
custom_delete_selected.short_description = "Delete selected items"

def get_actions(self, request):
    actions = super(AudioFileAdmin, self).get_actions(request)
    del actions['delete_selected']
    return actions

If you are not using the installation script, please copy following template file to your template directory:

cp audiofield/templates/common_audiofield.html /path/to/your/templates/directory/

Add the following in your template files (like admin/change_form.html, admin/change_list.html, etc... in which you are using audio field type):

{% block extrahead %}
{{ block.super }}
    {% include "common_audiofield.html" %}
{% endblock %}

Then perform following commands to create the table and collect the static files:

./ syncdb

and then:

./ collectstatic

Create audiofield.log file:

touch /var/log/audio-field.log


Extensive documentation is available on ‘Read the Docs’:


If you’ve found a bug, implemented a feature or customized the template and think it is useful then please consider contributing. Patches, pull requests or just suggestions are welcome!

Source code:

If you don’t like Github and Git you’re welcome to send regular patches.

Bug tracker:


Copyright (c) 2011-2014 Star2Billing S.L. <>

django-audiofield is licensed under MIT, see MIT-LICENSE.txt.


Django-audiofield is a Star2Billing-Sponsored Community Project, for more information visit or email us at