triump0870 triump0870 - 2 months ago 17
Python Question

django-image-cropping not working in admin interface

I'm using django-image-cropping in my django project and I followed the official guidelines but still I'm not getting the desired result.
Here the snippet of my project files.

I already added

easy_thumbnails
and
image_cropping
to my
INSTALLED_APPS
.

settings.py

from easy_thumbnails.conf import Settings as thumbnail_settings
THUMBNAIL_PROCESSORS = (
'image_cropping.thumbnail_processors.crop_corners',
) + thumbnail_settings.THUMBNAIL_PROCESSORS


models.py

from django.db import models
from image_cropping import ImageRatioField
class UserData(models.Model):
fullname = models.CharField(max_length=255)
user = models.CharField(max_length=70, unique=True, blank=False, null=False)
image = models.ImageField(upload_to=generate_filename,blank=False, null=False)
cropping = ImageRatioField('image', '180x180')


admin.py

from django.contrib import admin
from image_cropping import ImageCroppingMixin
class UserDataModelAdmin(ImageCroppingMixin, admin.ModelAdmin):
# filter_horizontal=['image']
pass

admin.site.register(UserData, UserDataModelAdmin)


As per the official guidelines its enough to see the enhanced selection area in the admin panel, but I'm not getting it. Instead I'm getting this.
enter image description here


No option for cropping.


Please help me to sort this out.

Answer

Use this tool django-imagekit-cropper, it has nice features and very good documentation. you need to create a form.py file and need to mention this

from django import forms
    from imagekit_cropper.widgets import ImageCropWidget    
    from .models import UserData


    class ImageAdminForm(forms.ModelForm):
        square_150_crop = forms.CharField(widget=ImageCropWidget(properties=Image.square_150_crop_properties, help_text=Image.help['square_150_crop']))

        class Meta:
            model = UserData
Comments