I have these models in 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
I am trying to see Appointment
as part of Number
's view (inline), so I follow Django tutorial part 2 and wrote this for my 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)
But now I am getting the following error whenever I try to view Number
via admin page:
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
I'm new to Django and have looked around the internet (Googled) quite a bit to figure out what I'm doing wrong here to cause such error. But I still couldn't figure this out after struggling with it for a few hours. If someone could help me explain what mistake I'm making here, I would really appreciate it. My goal is to be able to see related Appointment
entries whenever I view Number
via Django admin page. Thank you for your help.