我正在接触Django,并通过建立一个俱乐部会员网站来练习。在我为成员创建的应用程序的admin.py中,我收到以下错误:
'StudentAdmin.fieldsets [3] [1] ['fields']'指的是表单中缺少的字段'n'。
这是它引用的models.py部分(_CHOICES元组工作正常):
firstname = models.CharField(max_length=30)
surname = models.CharField(max_length=30)
dob = models.DateField(default='01/01/2000')
phone = models.CharField(max_length=13)
email = models.EmailField()
address = models.TextField()
grade = models.CharField(max_length=7,
choices=GRADE_CHOICES,
default='10THGUP')
school = models.CharField(max_length=3,
choices=SCHOOL_CHOICES,
default='RED')
insurancedate = models.DateField(default='01/01/2001')
emergencycontact = models.CharField(max_length=40)
emergencycontactnumber = models.CharField(max_length=13)
notes = models.TextField()
这是造成问题的admin.py:
from django.contrib import admin
from members.models import Student
class StudentAdmin(admin.ModelAdmin):
fieldsets = (
('Personal Details', {'fields': ('firstname', 'surname','dob','address','phone','email')
}),
('Training', {'fields': ('grade', 'school', 'insurancedate')
}),
('Emergency Contact', {'fields': ('emergencycontact', 'emergencycontactnumber',),
'classes': ('collapse')
}),
('Other', {'fields': ('notes')
}),
)
admin.site.register(Student, StudentAdmin)
我错过了什么蠢事吗?默认日期在models.py中,因为我使用python-evolution在第一个syncdb之后添加字段,并且它不想创建没有值的字段。
答案 0 :(得分:2)
可能应该行
('Other', {'fields': ('notes')
成为
('Other', {'fields': ('notes',)
所以它知道它的元组而不是字符串