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 3.2+
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
forPostgreSQL
databases. - Support upload by dropping file.
- Out of box HTMX support.
Future Roadmap
Intented Version | Description | Expected date |
---|---|---|
0.6.0 | Support for Drag and Drop for reordering on mobile phones. #153 | August, 2024 |
0.7.0 | Add support for the htmx swap initialization. #177 | August, 2024 |
0.7.X | Write test-cases for side-cases #151 | August, 2024 |
0.7.X | Review the documentation of the package. #171 | September, 2024 |
0.7.X | Grant light/dark theme support on Django 3.2 and Django 4.2+. #113 | September, 2024 |
1.0.0 | Drop support for Django 3.2 (no more supported by Django team). #152 | October, 2024 |
Installation
Install from PyPI:
pip install django-image-uploader-widget
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
File details
Details for the file django_image_uploader_widget-0.7.1.tar.gz
.
File metadata
- Download URL: django_image_uploader_widget-0.7.1.tar.gz
- Upload date:
- Size: 35.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7492776f2ebcc7e2e34472cd036c160c4a78fdf5f682fdd05b9ea15db113fd44 |
|
MD5 | a9eb9cbc4a0ba10839c367838bc620cc |
|
BLAKE2b-256 | 0b523c468e49ea13d8fdb349a403ae6e9a881a289b2543c878dde5831c11919b |
File details
Details for the file django_image_uploader_widget-0.7.1-py3-none-any.whl
.
File metadata
- Download URL: django_image_uploader_widget-0.7.1-py3-none-any.whl
- Upload date:
- Size: 47.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/5.1.1 CPython/3.9.19
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5da24971fe724e14ad7605090b47b8ed6e20d1b91a98506fdd3fe4ff6b97227b |
|
MD5 | c9f60fddde2b84edf1a609176419ec0e |
|
BLAKE2b-256 | 61067f19e7bc268166ced8ef968f35b8ebeeda35e7c38cf30dca21dd6af93b39 |