Skip to main content

A Django app that provides widgets for media files

Project description

django-media-tools is an app that provides useful widgets for managing media files in django admin. It doesn’t use any javascript library.

Works with Django 1.10 and newer versions.

Installation

  1. Install using pip:

    pip install django-media-tools
    
  2. Add media_tools to the INSTALLED_APPS:

    INSTALLED_APPS = [
       ...
       'media_tools',
    ]
    
  3. Run collectstatic command. It will copy the static files used by media_tools to your static root.:

    python manage.py collectstatic
    

PreviewImageWidget

PreviewImageWidget is a fairly simple widget that you can use for previewing an ImageField. The image-box is located at left of the Browse button as you can see below. If you click the image-box you will notice that the image will be open in a modal-box with a bigger size.

image-box: preview of the image

modal-box: it pops up when you click on the image-box

https://screenshotscdn.firefoxusercontent.com/images/c7cce7f5-cfe6-4de0-9d1b-1dc9529c87f4.png

Settings for PreviewImageWidget

Add DJANGO_MEDIA_TOOLS_CONFIG to your settings.py file if you want to set defaults for PreviewImageWidget.

DJANGO_MEDIA_TOOLS_CONFIG = {
    # max sizes of preview image-box
    'preview_max_height': '150px',
    'preview_max_width': '150px',

    # max size of preview modal-box (the box that is opened when clicked on image)
    'preview_modal_max_height': '90%',
    'preview_modal_max_width': '90%',

    # Hides 'currently' label on admin
    'hide_currently': False,

    # Shows the image url at the bottom of the modal if set to True
    'show_caption': True
}

How to use PreviewImageWidget

sample models.py

class Product(models.Model):
    name = models.CharField(_('name'), max_length=50)
    photo = models.ImageField(_('Photo'), upload_to='testing/product', blank=True)
    banner = models.ImageField(_('Banner'), upload_to='testing/product', blank=True)

sample forms.py

from media_tools.widgets import ImagePreviewWidget
from .models import Product

class ProductForm(forms.ModelForm):
    class Meta:
        model = Product
        fields = '__all__'
        widgets = {
            'photo': ImagePreviewWidget(preview_max_height='80px', preview_modal_max_height='600px', hide_currently=True, ),
            'banner': ImagePreviewWidget(preview_max_width='150px', preview_modal_max_width='50%', show_caption=False),
        }

As you can see you can override the default settings by giving them as kwargs.

Project details


Release history Release notifications

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Files for django-media-tools, version 0.1.0
Filename, size File type Python version Upload date Hashes
Filename, size django-media-tools-0.1.0.tar.gz (5.4 kB) File type Source Python version None Upload date Hashes View

Supported by

Pingdom Pingdom Monitoring Google Google Object Storage and Download Analytics Sentry Sentry Error logging AWS AWS Cloud computing DataDog DataDog Monitoring Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page