0
我建立了一個簡單的Django應用程序,現在有一個非常混亂的錯誤消息。我認爲這是因爲Tabularinline,但我根據to this documentation正確使用它。django管理失敗使用TabularInline
models.py
from django.db import models
class Person(models.Model):
company = models.CharField(max_length=120)
name = models.CharField(max_length=120)
birthday = models.DateField(null=True, blank=True)
def __unicode__(self):
return self.name
class Note(models.Model):
person = models.ForeignKey(Person)
datetime = models.DateTimeField()
text = models.TextField()
admin.py
from addressbook.models import Person, Note
from django.contrib import admin
class NoteInline(admin.TabularInline):
model = Note
class PersonAdmin(admin.ModelAdmin):
model = Person
inlines = [NoteInline, ]
admin.site.register(Note, NoteInline)
admin.site.register(Person, PersonAdmin)
但我總是收到此錯誤信息:
<類的addressbook.admin.NoteInline '>:(admin.E2 02)'addressbook.Note'沒有外鍵給'addressbook.Note'。
這也是我理解,但如果我使用它從Person
何必非要Note
對自身的引用?
我不認爲你需要單獨註冊'NoteInline'管理模板。只需註冊'PersonAdmin'模板,並且應該包含'NoteInline'。 – 2015-02-05 20:26:19