django-grappeliとsorl-thumbnailを使用したDjango1.3で問題が発生しました。私は公式のsorl-thumbnailsドキュメントからこのコードを使用するプロジェクトを持っています:
# myapp/admin.py
from django.contrib import admin
from myapp.models import MyModel
from sorl.thumbnail.admin import AdminImageMixin
class MyModelAdmin(AdminImageMixin, admin.ModelAdmin):
pass
このプロジェクトはデバッグサーバーでうまく機能し、管理者の変更フォームに素敵な小さなサムネイルが表示されます。
ただし、別のプロジェクトでは、WSGIを介してプロジェクトにサービスを提供しており、3つの別個のドメインがあります。
www.example.com
media.example.com (that's serving user uploaded files)
static.example.com (that's serving static files)
ただし、このプロジェクトでは、モデルの変更フォームでサムネイルが使用できない場合を除いて、AdminImageMixinは正常に機能します。
- 正しい場所に画像をアップロードします
- データベースフィールド(uploads / + picture_name.jpg)に正しいテキストを入力します(これをphpmyadminで確認しました)
- 参照ボタン以外のサムネイルはフォームに表示されません(私が慣れているように)
サンプルコードは次のとおりです。
# models.py
class Category(models.Model):
name = models.CharField(max_length=200, verbose_name='name', help_text='Name of category')
description = models.TextField(verbose_name='Description', help_text='You can use Textile')
icon = ImageField(upload_to='uploads/', blank=True, null=True)
# admin.py
class CategoryAdmin(AdminImageMixin, admin.ModelAdmin):
pass
admin.site.register(Category, CategoryAdmin)
# settings.py
INSTALLED_APPS = (
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.sites',
'django.contrib.messages',
'django.contrib.staticfiles',
'grappelli',
# Uncomment the next line to enable the admin:
'django.contrib.admin',
'django_evolution',
'django_extensions',
'sorl.thumbnail',
# Uncomment the next line to enable admin documentation:
# 'django.contrib.admindocs',
)
私が間違っているアイデアはありますか?
前もって感謝します。