3
我試圖使用sorl-thumbnail v11.12在Django管理員中顯示縮略圖。在Django中的sorl-thumbnail admin使用AdminImageMixin
我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中顯示縮略圖。
MyProject的/ 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
MyProject的/ 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)
請提供一些解釋,這個代碼是如何工作的。在StackOverflow中,代碼傾銷通常是令人沮喪和不滿意的 – rayryeng