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.
No option for cropping.
Please help me to sort this out.
Though this isn't covered in the documentation, I found that I needed to add the cropping
attribute from my model to my custom UserAdmin
fieldsets:
fieldsets = (
(None, {'fields': ('email', 'password')}),
('Personal info', {'fields': ('first_name', 'last_name', 'gender',
'phone', 'address', 'postal_code', 'city', 'student', 'university',
'newsletter', 'birthday', 'avatar', 'cropping')}),
Where my image
attribute is alternatively names avatar
.
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
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With