0

当我使用 sorl-thumbnail 尝试格式化我的 django 管理员个人资料图像时,我收到此错误“employee_directory.thumbnail_kvstore'不存在”。有没有人在使用 sorl-thumbnail 和 django admin changelist 时遇到这个问题?

DatabaseError at /directory/employee/
(1146, "Table 'employee_directory.thumbnail_kvstore' doesn't exist")

我仔细检查了我的 sorl-thumbnail 安装,并确保我做了一个同步数据库。以下是我的 models.py 和 admin.py 中的代码

模型.py:

from django.db import models
from sorl.thumbnail import ImageField

# Department Table
class Department(models.Model):
    department_name = models.CharField(max_length=128)

    def __unicode__(self):
        return self.department_name

# Employee Directory Table
class Employee(models.Model):
    last_name = models.CharField(max_length=32)
    first_name = models.CharField(max_length=32)
    profile_image = models.ImageField(upload_to="images/profile_image", blank=True)
    department_name = models.ForeignKey('Department')
    job_title = models.CharField(max_length=64)
    office_number = models.CharField(max_length=8, blank=True)
    fax_number = models.CharField(max_length=8, blank=True)
    mobile_number = models.CharField(max_length=8, blank=True)
    intercom_number = models.CharField(max_length=3, blank=True)
    email = models.CharField(max_length=128)
    memo = models.TextField(blank=True)


    def __unicode__(self):
        return self.last_name + ', ' + self.first_name

管理员.py:

from directory.models import *
from django.contrib import admin
from sorl.thumbnail import get_thumbnail


class EmployeeAdmin(admin.ModelAdmin):

    def profile_img(self, obj):
        if obj.profile_image:
            t = get_thumbnail(obj.profile_image,"50x50",crop='center', quality=99)
            return u'<img src="/media%s"/>' % t.url
        else:
            return u'profile_image'
    profile_img.short_description = 'Profile image'
    profile_img.allow_tags = True


    search_fields = ['last_name', 'first_name']
    list_display = ['profile_img', 'last_name', 'first_name', 'department_name', 
                    'job_title', 'office_number', 'fax_number', 
                    'mobile_number', 'intercom_number', 'email']
    list_filter = ['department_name']




admin.site.register(Department)
admin.site.register(Employee, EmployeeAdmin)

任何帮助是极大的赞赏。

4

1 回答 1

2

我完全没用,我忘了把 sorl.thumbnail 放在我的应用程序的 django 设置中。

于 2013-03-04T07:11:14.413 回答