2015-02-05 39 views
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对自身的引用?

+1

我不认为你需要单独注册'NoteInline'管理模板。只需注册'PersonAdmin'模板,并且应该包含'NoteInline'。 – 2015-02-05 20:26:19

回答

1

我不认为你需要单独注册NoteInline管理模板。只需注册PersonAdmin模板,那应该包括你的NoteInline