Simplify ImageField Visualization with django-admin-thumbnail
Are you tired of struggling with ImageField visualization in your Django ModelAdmin? Look no further! The django-admin-thumbnail package is here to simplify the process and provide user-friendly thumbnails for your ImageField columns.
Getting Started
To get started, simply install the django-admin-thumbnail package by adding it to your INSTALLED_APPS
in the settings.py
file of your Django project.
python
INSTALLED_APPS = (
...
'admin_thumbnail',
...
)
Next, switch from using the standard ModelAdmin
to the ThumbAdmin
subclass provided by django-admin-thumbnail. This subclass automatically generates thumbnails for any ImageField you include in your list_display
.
“`python
from models import ModelExample
from admin_thumbnail import thumb_admin
from django.contrib import admin
class ModelExampleAdmin(thumb_admin.ThumbAdmin):
list_display = (‘an_image_field’,)
admin.register(ModelExample, ModelExampleAdmin)
“`
Usage
Once you have updated your ModelAdmin
and settings.py
, you need to create the database table that manages the cached thumbnails using the following command:
python manage.py syncdb
If you are using the south
package, you will need to initialize sorl.thumbnail
migrations and apply them to your database. Use the following commands:
python manage.py schemamigration sorl.thumbnail --initial
python manage.py migrate sorl.thumbnail --database=$DATABASE_NAME
Please note that if you are using a custom database name or a database router, you should add a key named thumbnail
to your database mapping dictionary.
And that’s it! Your ImageFields will now display user-friendly thumbnails in your Django ModelAdmin.
Installation and Requirements
Before installing django-admin-thumbnail, make sure you have satisfied the following requirements:
- Django 1.4+
- sorl.thumbnail 11.12+
- PIL 1.1.6+
To install django-admin-thumbnail using pip, run the following command:
pip install django-admin-thumbnail
Alternatively, you can clone the project from GitHub and install it using python setup.py install
.
Localization
django-admin-thumbnail is localizable, and currently supports the following languages: pt_BR, en_US, and es. However, you can easily localize it in any language of your choice by creating a .po file. If you create a localization file, please consider sending it to the package creator to make it officially supported.
Contact
If you have any comments, ideas, questions, or feedback about django-admin-thumbnail, feel free to reach out to the package creator at django-admin-thumbnail@flaviocaetano.com.
Now you can simplify your ImageField visualization in Django with ease using django-admin-thumbnail. Install it today and start enhancing the user experience of your Django ModelAdmin.
Leave a Reply