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.
我在我的django项目中使用django-image-cropping,我遵循官方指南,但仍然没有得到理想的结果。这是我的项目文件的片段。
I already added easy_thumbnails
and image_cropping
to my INSTALLED_APPS
.
我已经将easy_thumbnails和image_cropping添加到了我的INSTALLED_APPS中。
settings.py
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
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
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.
请帮我解决这个问题。
2 个解决方案
#1
0
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
使用此工具django-imagekit-cropper,它具有很好的功能和非常好的文档。你需要创建一个form.py文件,需要提一下
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
#2
0
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:
虽然文档中没有介绍,但我发现需要将模型中的cropping属性添加到自定义的UserAdmin字段集中:
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
.
我的图像属性也可以是头像。
#1
0
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
使用此工具django-imagekit-cropper,它具有很好的功能和非常好的文档。你需要创建一个form.py文件,需要提一下
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
#2
0
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:
虽然文档中没有介绍,但我发现需要将模型中的cropping属性添加到自定义的UserAdmin字段集中:
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
.
我的图像属性也可以是头像。