django-image-cropping无法正常工作

时间:2014-06-13 19:00:27

标签: python django image

尝试使用django-image-cropping。我没有得到任何错误,我只是在Django Admin中看起来像CharField而不是django-image-cropping功能:

enter image description here

base.py(设置):

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

easy_thumbnailsimage_cropping添加到INSTALLED_APPS

models.py:

from image_cropping import ImageRatioField
# ...
class Organization(models.Model):
    image_cover = models.ImageField(upload_to='media', blank=True, help_text="blah")
    cropping = ImageRatioField('image_cover', '308x850')

admin.py:

from django.contrib import admin
from image_cropping import ImageCroppingMixin

class OrganizationAdmin(ImageCroppingMixin, admin.ModelAdmin):
    pass

class OrganizationAdmin(admin.ModelAdmin):
    filter_horizontal=['categorys']
    #...

admin.site.register(Organization, OrganizationAdmin)

1 个答案:

答案 0 :(得分:2)

您在OrganizationAdmin中定义了admin.py两次。一次,正确地,继承ImageCroppingMixin并且一次没有。由于后一种定义会覆盖前者,因此最终没有使用Mixin。这就是它应该是这样的:

from django.contrib import admin
from image_cropping import ImageCroppingMixin

class OrganizationAdmin(ImageCroppingMixin, admin.ModelAdmin):
    filter_horizontal=['categorys']
    #...

admin.site.register(Organization, OrganizationAdmin)