Skip to main content

Simple Image Uploader Widget for Django-Admin

Project description

Simple Image Upload Widget

Inline Multiple Images Upload

Introduction

One of the things that i did't like in the django-admin is the arcaic appearance and usability of the forms, specially in the image upload, then i decided to create this plugin (for a use in a personal project, but i decided to publish here).

Some Informations

Warning: This was developed using the more recent version of django and i have not tested this with older django versions (because i created this for use in some recent projects). Is not my intentions to made this complete compatible with old versions of django, but if you want to try to use this with older versions of django and get some erros, please contact-me (or open a issue here) and we can talk about the errors and made this compatible to the version that you are geting errors.

Install

1. Install using the pip:

pip install django-image-uploader-widget

2. Add this to the INSTALLED_APPS:

Go to your settings.py and add image_uploader_widget to installed apps, then they like this:

INSTALLED_APPS = [
    'my_app.apps.MyAppConfig',
    'django.contrib.admin',
    'django.contrib.auth',
    'django.contrib.contenttypes',
    'django.contrib.sessions',
    'django.contrib.messages',
    'django.contrib.staticfiles',
    'django.forms',
    'image_uploader_widget',
]

Using for single Image File Uploader

1. Create the model in the models.py

from django.db import models 

class ExampleModel(models.Model):
    image = models.ImageField('Image', null = True, blank = True)

    def __str__(self):
        return 'Example Model'

    class Meta:
        verbose_name = 'Example Model'
        verbose_name_plural = 'Example Models'

2. Create the form in the forms.py

from django import forms
from image_uploader_widget.widgets import ImageUploaderWidget

class ExampleForm(forms.ModelForm):

    class Meta:
        widgets = {
            'image': ImageUploaderWidget(),
        }
        fields = '__all__'

3. Create the admin in the admin.py

from django.contrib import admin
from . import models
from . import forms

class ExampleAdmin(admin.ModelAdmin):
    form = forms.ExampleForm

admin.site.register(models.ExampleModel, ExampleAdmin)

Using for multiple Image File Uploader Inline

This is designed to be used with a model to store ONLY the image. See a example:

1. The model in models.py

from django.db import models

class ExampleModel(models.Model):
    image = models.ImageField('Image', null = True, blank = True)

    def __str__(self):
        return 'Example Model'

    class Meta:
        verbose_name = 'Example Model'
        verbose_name_plural = 'Example Models'

class ExampleModelImage(models.Model):
    example = models.ForeignKey(ExampleModel, on_delete = models.CASCADE)
    image = models.ImageField('Image')

Note: See that the ExampleModelImage is a model created to store only images, that are linked to the ExampleModel, like the photos of a product in a shop basic model.

2. Defining the inline editor in the admin.py

from django.contrib import admin
from image_uploader_widget.admin import ImageUploaderInline

from . import models
from . import forms

class ExampleModelImageAdmin(ImageUploaderInline):
    model = models.ExampleModelImage
    fields = ['image']

class ExampleAdmin(admin.ModelAdmin):
    form = forms.ExampleForm
    inlines = [ExampleModelImageAdmin]

admin.site.register(models.ExampleModel, ExampleAdmin)

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

django-image-uploader-widget-0.1.1.tar.gz (18.2 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file django-image-uploader-widget-0.1.1.tar.gz.

File metadata

  • Download URL: django-image-uploader-widget-0.1.1.tar.gz
  • Upload date:
  • Size: 18.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for django-image-uploader-widget-0.1.1.tar.gz
Algorithm Hash digest
SHA256 5734efc37ddfe7e710b8d1ce5e1f58de2ab1d7729a11746b738470deba5dc1c8
MD5 71a8a93f4f99a9426cbe927474fc975e
BLAKE2b-256 477f2cb36acb5e3407bfd7932bd86255bf4ba4af64815561dd598aeaa0bc9c86

See more details on using hashes here.

File details

Details for the file django_image_uploader_widget-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: django_image_uploader_widget-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 27.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.7.1 importlib_metadata/4.10.0 pkginfo/1.8.2 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.9.9

File hashes

Hashes for django_image_uploader_widget-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 3ad866f4344a0ce9026093e9f78b0344de857d6d8296c74515340b09a57d8886
MD5 e57a616d10addca10a4ea8b67fd1e34d
BLAKE2b-256 2858dba38ada745a1cfd5501b01e6e8c9e47346febf45b4e69877eb26c0fa65b

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page