Friday, January 29, 2010

'Reverse' (??) InlineModelAdmin objects

Hey guys,
I've been trying to get InlineModelAdmin objects setup in my admin
app, but am unable to figure out how to do so correctly. Using the
same example as the one listed in the docs [1]:

class Author(models.Model):
name = models.CharField(max_length=100)

class Book(models.Model):
author = models.ForeignKey(Author)
title = models.CharField(max_length=100)

What I would like to do is have the Author creation form show up in
with the Book creation form - so basically, my admin.py code would
look something like:

class AuthorInline(admin.TabularInline):
model = Author

class BookAdmin(admin.ModelAdmin):
...
inlines = [AuthorInline, ]

However, when I try this, I get an error:

Exception Value: <class 'testapp.models.Author'> has no ForeignKey to
<class 'testapp.models.Book'>.

So, I was wondering if anyone knows how I could get an Author creation
form show up inline with on the 'Add Book' page.

Thanks.

--

Best,

R

[1] - http://docs.djangoproject.com/en/dev/ref/contrib/admin/#inlinemodeladmin-objects

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate