gpt4 book ai didi

Django issubclass() arg 1 must be a class error in insering TabularInline at admin 页面

转载 作者:行者123 更新时间:2023-12-03 23:54:24 31 4
gpt4 key购买 nike

我在 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 View (内联)的一部分,因此我遵循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 管理页面查看 Number 时都能看到相关的 Appointment 条目。感谢您的帮助。

最佳答案

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

inlines = [AppointmentInline,]

代替:

inlines = ['AppointmentInline',]

关于Django issubclass() arg 1 must be a class error in insering TabularInline at admin 页面,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17340298/

31 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com