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


Download files

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

Source Distribution

django-media-tools-0.1.0.tar.gz (5.4 kB view details)

Uploaded Source

File details

Details for the file django-media-tools-0.1.0.tar.gz.

File metadata

File hashes

Hashes for django-media-tools-0.1.0.tar.gz
Algorithm Hash digest
SHA256 de53b3d5ba7105c17ac7c78ba621283cf4ea418178e2a7b80d228f54fe89a6f3
MD5 6f140ab04225c7046558e68cc520333c
BLAKE2b-256 1c410d5e0a257b61ea85954fc5b3ddf202df3cbec1b75027fedfcae918126bfd

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page