我正在关注“django by example”教程的这一部分。现在当我去/admin/todo/datetime/
点击Add date time
我得到这个错误:
Exception Type: Exception at /admin/todo/datetime/add/
Exception Value: <class 'todo.models.Item'> has no ForeignKey to <class 'todo.models.DateTime'>
我的代码几乎相同(除了我包含导入语句):
from django.db import models
from django.contrib import admin
class DateTime(models.Model):
datetime = models.DateTimeField(auto_now_add = True)
def __unicode__(self):
return unicode(self.datetime)
class Item(models.Model):
name = models.CharField(max_length = 60)
created = models.DateTimeField(auto_now_add = True)
priority = models.IntegerField(default = 0)
difficulty = models.IntegerField(default = 0)
done = models.BooleanField(default = False)
class ItemAdmin(admin.ModelAdmin):
list_display = ["name", "priority", "difficulty", "created", "done"]
search_fields = ["name"]
class ItemInline(admin.TabularInline):
model = Item
class DateAdmin(admin.ModelAdmin):
list_display = ["datetime"]
inlines = [ItemInline]
admin.site.register(Item, ItemAdmin)
admin.site.register(DateTime, DateAdmin)
我查看了类似的 SO 线程,但我无法从那里弄清楚这里出了什么问题。(顺便说一句,我在教程中使用了django 1.3
while django 1.2
)