Django MultipleImageInput
Widget for multiple image fields. Works good with PostgreSQL array fields.
Example
In this example i use crispy_forms
settings.py
import pathlib
import os
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
MEDIA_URL = '/media/'
MEDIA_ROOT = pathlib.Path(BASE_DIR) / 'common' / 'media'
model.py
from django.contrib.postgres.fields import ArrayField
from django.db import models
class Product(models.Model):
class Meta:
db_table = 'product'
verbose_name = 'товар'
verbose_name_plural = 'товары'
IMAGE_PATH = 'common/image/product'
title = models.TextField('заголовок', null=True, blank=True)
description = models.TextField('описание', null=True, blank=True)
price = models.IntegerField('цена')
youtube_url = models.URLField('видео youtube', null=True, blank=True)
image_list = ArrayField(models.TextField("картинки"), default=list, verbose_name='картинки', blank=True)
view.py
from settings import MEDIA_ROOT
from models import Product
import django_multipleimageinput
class UploadImageView(django_multipleimageinput.UploadImageView):
media_root = MEDIA_ROOT
image_path = Product.IMAGE_PATH
forms.py
from django import forms
from models import Product
from django_multipleimageinput import MultipleImageInput
from django.urls import reverse_lazy
from crispy_forms.helper import FormHelper
from crispy_forms.layout import ButtonHolder, Submit, Layout
class ProductForm(forms.ModelForm):
class Meta:
model = Product
fields = ["title", "description", "price", "youtube_url", "image_list"]
widgets = {
"title": forms.TextInput(),
"description": forms.Textarea(attrs={'rows': 4, 'cols': 15}),
"image_list": MultipleImageInput(reverse_lazy('common:product/upload-image'), MEDIA_URL)
}
def __init__(self, *args, **kwargs):
self.helper = FormHelper()
self.helper.layout = Layout(
'title',
'description',
'price',
'youtube_url',
'image_list',
ButtonHolder(
Submit('submit', 'Сохранить')
)
)
super(ProductForm, self).__init__(*args, **kwargs)
urls.py
from django.urls import path
from django.conf.urls.static import static as sttc
import views
import settings
app_name = 'common'
urlpatterns = [
path('product/upload-image', views.UploadImageView.as_view(), name='product/upload-image'),
] + sttc(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
Metadata
Release files for django-multipleimageinput 0.0.2
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_multipleimageinput-0.0.2.tar.gz | 6.8 kB | Without provenance | Details for django_multipleimageinput-0.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_multipleimageinput-0.0.2-py3-none-any.whl | Python 3 | none | any | Details for django_multipleimageinput-0.0.2-py3-none-any.whl |
Total release size: 15.0 kB
Release files / django_multipleimageinput-0.0.2.tar.gz
| Download URL | django_multipleimageinput-0.0.2.tar.gz |
|---|---|
| Size | 6.8 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
8916d5f197d9a5f883b09e0abd2cbce040b6d08fbda391a4741e3568de58c6b6
|
|
BLAKE2b-256 checksum How to use checksums |
458e1f591051cc22f11aee6f6338ebc14c0a77e63eb5e3ddcf4188bf079e81a9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.25.0 CPython/3.7.5
|
Release files / django_multipleimageinput-0.0.2-py3-none-any.whl
| Download URL | django_multipleimageinput-0.0.2-py3-none-any.whl |
|---|---|
| Size | 8.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
07eb316a0237dacc8c7ad77b766aff480163bad318dfc0e92270ee52de0b964a
|
|
BLAKE2b-256 checksum How to use checksums |
9086a161df8832e2a59e3bae315f3ab6542051ae61a2a4dc46d4db3ac10beccf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.13.0 pkginfo/1.5.0.1 requests/2.22.0 setuptools/41.0.1 requests-toolbelt/0.9.1 tqdm/4.25.0 CPython/3.7.5
|
Security for django-multipleimageinput 0.0.2
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.