tjati
tjati

Reputation: 6079

django admin fails using TabularInline

I built a simple django application and now have a really confusing error message. I think it's because of Tabularinline, but I use it properly according to this documentation.

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)

But I always get this error message:

<class 'addressbook.admin.NoteInline'>: (admin.E202) 'addressbook.Note' has no ForeignKey to 'addressbook.Note'.

Which I would understand but why should have Note a reference to itself If I am using it from Person?

Upvotes: 0

Views: 277

Answers (1)

Scott Harris
Scott Harris

Reputation: 319

I don't think you need to separately register the NoteInline admin template. Just register the PersonAdmin template and that should include your NoteInline

Upvotes: 1

Related Questions