Simple Image Uploader Widget for Django-Admin
Project description
django-image-uploader-widget
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
ImageFieldinside inlines django-admin; - Support preview modal;
- Support custom inline for django-admin usage.
- Support reordering inside django-admin inline.
- Support
ArrayFieldforPostgreSQLdatabases. - Support upload by dropping file.
- Out of box HTMX support.
Installation
Install from PyPI:
pip install django-image-uploader-widget
On the
1.0.0release of this package we droped the support forDjango 3.2,Django 4.0andDjango 4.1. We, currently, maintain the support forDjango 4.2(LTS),Django 5.0andDjango 5.1. Then, if you are usingDjango 3.2,4.0or4.1, installs0.7.1version: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 image_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 image_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 image_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 image_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
Behaviour
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file django_image_uploader_widget-1.1.1.tar.gz.
File metadata
- Download URL: django_image_uploader_widget-1.1.1.tar.gz
- Upload date:
- Size: 35.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6c1112c5e30a8b95f9d01c987096aa11576093fae501093efe86e5e5441d1b50
|
|
| MD5 |
2be437851525ae2ab69cc0162c22b0d1
|
|
| BLAKE2b-256 |
9a118076ada7efc096855c90afdaeab3c4a2102f61677ffc853a476f6fbfe8ec
|
File details
Details for the file django_image_uploader_widget-1.1.1-py3-none-any.whl.
File metadata
- Download URL: django_image_uploader_widget-1.1.1-py3-none-any.whl
- Upload date:
- Size: 47.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.25
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
c20f1a43c0633a54d04daf7f5231a9127aefd406576e312b2f751cf6b8e351d7
|
|
| MD5 |
e0c40c0e0d0bf791ce82c424f06abcd4
|
|
| BLAKE2b-256 |
82907def4e29a6c83addba67ec3bbaf6ba9c710dd6a12044b813654a1841a62b
|