我正在尝试使用sorl-thumbnail v11.12在 Django 管理员中显示缩略图。
我models.py
已经按照文档使用了 sorl.thumbnail.ImageField:
Note You do not need to use the sorl.thumbnail.ImageField to use sorl.thumbnail. The standard django.db.models.ImageField is fine except that using the sorl.thumbnail.ImageField lets you plugin the nice admin addition explained in the next section.
但是,我不确定如何配置admin.py
. 我已经做了一个manage.py syncdb
。目前,我有以下内容,但它没有在 Django 管理中显示缩略图。
我的项目/admin.py
from django.contrib.admin import *
from sorl.thumbnail.admin import AdminImageMixin
class ModelAdmin(AdminImageMixin, ModelAdmin):
pass
class TabularInline(AdminImageMixin, TabularInline):
pass
class StackedInline(AdminImageMixin, StackedInline):
pass
我的项目/myapp/admin.py
from MyProject import admin
from myapp.models import Tours
class ToursAdmin(admin.ModelAdmin):
list_display = ('name', 'image', 'price')
search_fields = ('name',)
admin.site.register(Tours, ToursAdmin)