django-media-tools
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
Install using pip:
pip install django-media-tools
Add media_tools to the INSTALLED_APPS:
INSTALLED_APPS = [ ... 'media_tools', ]
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
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.
Metadata
Release files for django-media-tools 0.1.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| django-media-tools-0.1.0.tar.gz | 5.4 kB | Without provenance | Details for django-media-tools-0.1.0.tar.gz |
Release files / django-media-tools-0.1.0.tar.gz
| Download URL | django-media-tools-0.1.0.tar.gz |
|---|---|
| Size | 5.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
de53b3d5ba7105c17ac7c78ba621283cf4ea418178e2a7b80d228f54fe89a6f3
|
|
BLAKE2b-256 checksum How to use checksums |
1c410d5e0a257b61ea85954fc5b3ddf202df3cbec1b75027fedfcae918126bfd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for django-media-tools 0.1.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.