Django issubclass()arg 1在管理页面中输入TabularInline时必须是类错误

时间:2013-06-27 10:06:02

标签: django django-models django-admin

我在Django 1.5中有这些模型

class Number(models.Model):
    number = models.CharField("Patient's Number", max_length=12, unique=True)
    created = models.DateTimeField("Date created", auto_now=True)
    created.editable = True

class Appointment(models.Model):
    to_number = models.ForeignKey(Number)
    message = models.CharField("Message", max_length=160)
    send_on = models.DateTimeField("Date/Time to send the message")
    email = models.CharField("Email to forward the response to", max_length=254, blank=True)
    reply_to = models.CharField("Phone number to forward the response to", max_length=12, blank=True)

    created = models.DateTimeField("Date created", auto_now=True)
    created.editable = True

class MyLog(models.Model):
    to_number = models.CharField("To Number", max_length=12, blank=True)
    from_number = models.CharField("From Number", max_length=12, blank=True)
    email = models.CharField("Email to forward the response to", max_length=254, blank=True)
    message_id = models.CharField("Message ID", max_length=66)
    message_content = models.CharField("Message Content", max_length=160)
    message_status = models.CharField("Message status per Twilio", max_length=50)

    created = models.DateTimeField('Date created', auto_now=True)
    created.editable = True

我试图将Appointment视为Number视图(内联)的一部分,因此我按照Django tutorial part 2为我的admin.py写了这个:

from django.contrib import admin
from sms.models import Number, Appointment, MyLog

class AppointmentInline(admin.TabularInline):
    model = Appointment
    exclude = ('created',)

class NumberAdmin(admin.ModelAdmin):
    list_display = ('id', 'number', 'created',)
    list_display_links = ('id',)
    list_editable = ('number',)
    search_fields = ['number']
    save_on_top = True
    readonly_fields = ('created',)
    inlines = ['AppointmentInline',] # SEEMS LIKE THIS LINE IS CAUSING THE PROBLEM

class AppointmentAdmin(admin.ModelAdmin):
    fieldsets = (
        ('Essential Information', {
            'fields': ('to_number', 'message', 'send_on', 'reply_to', 'email'),
            'classes': ('wide', 'extrapretty')}),
        ('Non-Essential Information', {
            'fields': ('created',),
            'classes': ('collapse',)}),
        )
    list_display =  ('to_number', 'message', 'send_on', 'reply_to', 'email',)
    list_display_links = ('to_number',)
    list_editable = ('message', 'send_on', 'reply_to', 'email',)
    search_fields = ['to_number__number', 'message', 'reply_to', 'email']
    save_on_top = True
    readonly_fields = ('created',)

class MyLogAdmin(admin.ModelAdmin):
    list_display = ('to_number', 'from_number', 'email', 'message_content', 'message_status', 'created',)
    fields = ('to_number', 'from_number', 'email', 'message_content', 'message_status', 'created',)
    search_fields = ['to_number', 'from_number', 'email', 'message_content', 'message_status']
    readonly_fields = ('to_number', 'from_number', 'email', 'message_content', 'message_status', 'created',)

admin.site.register(Number, NumberAdmin)
admin.site.register(Appointment, AppointmentAdmin)
admin.site.register(MyLog, MyLogAdmin)

但是现在每当我尝试通过管理页面查看Number时,我都会收到以下错误:

TypeError at /admin/sms/number/
...
Exception Type:     TypeError
Exception Value:    

issubclass() arg 1 must be a class

Exception Location:     /home/phyo/.virtualenvs/t4stest/lib/python2.7/site-packages/django/contrib/admin/validation.py in validate, line 179
Python Executable:  /usr/bin/uwsgi

我是Django的新手并且已经浏览了互联网(谷歌搜索)了解我在这里做错了什么导致这样的错误。但是经过几个小时的努力,我仍然无法弄清楚这一点。如果有人能帮助我解释我在这里犯的错误,我会非常感激。我的目标是每当我通过Django管理页面查看Appointment时都能看到相关的Number条目。谢谢你的帮助。

1 个答案:

答案 0 :(得分:6)

内联不能是字符串,即。用这个:

inlines = [AppointmentInline,]

而不是:

inlines = ['AppointmentInline',]