我正在關注this部分'django by example'教程。現在,當我去/admin/todo/datetime/
,並點擊Add date time
我得到這個錯誤:django:運行'django示例'時沒有ForeignKey'錯誤教程代碼
Exception Type: Exception at /admin/todo/datetime/add/
Exception Value: <class 'todo.models.Item'> has no ForeignKey to <class 'todo.models.DateTime'>
我的代碼是幾乎相同的(除了我有import語句包括):
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)
我看着相似所以線程,但我不知道從那裏出了什麼問題。 (順便說一句,我用django 1.3
而django 1.2
在turorial使用)