Skip to main content

django-image-uploader-widget

Supported Python Versions Supported Django Versions PyPI - Version GitHub License PyPI - Downloads GitHub Actions Workflow Status

Introduction

django-image-uploader-widget provides a beautiful image uploader widget for django and a multiple image inline editor for django-admin.

Requirements

  • Python 3.8+
  • Django 4.2+
  • Django 3.2,4.0,4.1 (uses django-image-uploader-widget<=0.7.1)

Features

  • Support required and optional ImageField;
  • Support for ImageField inside inlines django-admin;
  • Support preview modal;
  • Support custom inline for django-admin usage.
  • Support reordering inside django-admin inline.
  • Support ArrayField for PostgreSQL databases.
  • Support upload by dropping file.
  • Out of box HTMX support.

Installation

Install from PyPI:

pip install django-image-uploader-widget

On the 1.0.0 release of this package we droped the support for Django 3.2, Django 4.0 and Django 4.1. We, currently, maintain the support for Django 4.2 (LTS), Django 5.0 and Django 5.1. Then, if you are using Django 3.2, 4.0 or 4.1, installs 0.7.1 version:

pip install django-image-uploader-widget==0.7.1

Add image_uploader_widget to INSTALLED_APPS:

INSTALLED_APPS = [
    # ...
    'image_uploader_widget',
    # ...
]

Basic Usage

With Admin

The ImageUploaderWidget is a class that implements a custom widget for single image uploader and can be used inside the formfield_overrides attribute inside the ModelAdmin class.

# admin.py
from django.contrib import admin
from django.db import models
from media_uploader_widget.widgets import ImageUploaderWidget
from .models import YourModel


@admin.register(YourModel)
class YourModelAdmin(admin.ModelAdmin):
    formfield_overrides = {
        models.ImageField: {'widget': ImageUploaderWidget},
    }

See the documentation for more complex usage's.

With ModelForm

The ImageUploaderWidget can be used inside the widgets Meta attribute of a Form/ModelForm:

# forms.py
from django import forms
from media_uploader_widget.widgets import ImageUploaderWidget


class ExampleForm(forms.ModelForm):
    class Meta:
        widgets = {
            'image': ImageUploaderWidget(),
        }
        fields = '__all__'

See the documentation for more complex usage's.

Custom Inline Admin

The ImageUploaderInline is implemented with the base of the admin.StackedInline to create an custom django-admin to work with multiple images upload using a model only to store the images:

# models.py

class Product(models.Model):
    # ...

class ProductImage(models.Model):
    product = models.ForeignKey(
        Product,
        related_name="images",
        on_delete=models.CASCADE
    )
    image = models.ImageField("image")
    # ...
# admin.py
from django.contrib import admin
from media_uploader_widget.admin import ImageUploaderInline
from .models import Product, ProductImage


class ProductImageAdmin(ImageUploaderInline):
    model = ProductImage


@admin.register(Product)
class ProductAdmin(admin.ModelAdmin):
    inlines = [ProductImageAdmin]

See the documentation for more complex usage's.

Array Field

The ArrayField support is made by a custom field, called ImageListField. Then, to use it, we need to change the field from default ArrayField to ImageListField. The reason for it is: the default ArrayField with ImageField not works and some part of the behaviour of the ImageField is implemented inside the ImageListField.

# models.py
from django.db import models
from media_uploader_widget.postgres import ImageListField


class TestWithArrayField(models.Model):
    images = ImageListField(blank=True, null=True, upload_to="admin_test")

    class Meta:
        verbose_name = "Test With Array Field"

See the documentation for more complex usage's.

Documentation

All the documentation of basic and advanced usage of this package is disponible at documentation.

Preview

Widget with Image in Dark ThemeWidget with Image in Light Theme

Widget in Dark ThemeWidget in Light Theme

Behaviour

Widget Behaviour

Custom Admin Inline Behaviour

Metadata

Release files for django-media-uploader-widget 1.0.2

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for django-media-uploader-widget 1.0.2
File Size Uploaded
django_media_uploader_widget-1.0.2.tar.gz 38.0 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for django-media-uploader-widget 1.0.2
File Interpreter ABI Platform
django_media_uploader_widget-1.0.2-py3-none-any.whl Python 3 none any Details

Total release size: 88.9 kB

Release files / django_media_uploader_widget-1.0.2.tar.gz

Download URL django_media_uploader_widget-1.0.2.tar.gz
Size 38.0 kB
Tags Source
SHA-256 checksum
How to use checksums
7fa083a45ad7415fa9392cc49cea9dea37765542d852640077fccd07b9608164
BLAKE2b-256 checksum
How to use checksums
806ba759c2a7a31d7ab2e026dd1be6e49d63167733466dce3b9b0d3da5479e5d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.21

Release files / django_media_uploader_widget-1.0.2-py3-none-any.whl

Download URL django_media_uploader_widget-1.0.2-py3-none-any.whl
Size 50.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5e9170b8dd9c7c726dcf3e88746188c17df339ae5c689ff1e020082f0dbfa5cb
BLAKE2b-256 checksum
How to use checksums
4dec1a4a8dada6b8a089efe00f7f76845796e33416648b52cc7c6db518c59ae6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.9.21

Release history Release notifications | RSS feed

This release

1.0.2 This release

2 release files

1.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page