Slight correction. In your first example:
class Chapter(models.Model):
>book = models.ForeignKey(Chapter)
>
The parameter to ForeignKey should be book:
class Chapter(models.Model):
book = models.ForeignKey(Book)
As mentioned earlier, you can locate a chapter's book as chapter.bo
Thanks for confirming.
Book.chapter_set.all()
gets all of the chapters for the book. Thanks!
mike
[EMAIL PROTECTED] wrote:
> The first way is the correct way, to get all the chapters for a given
> book you would do book_obj.chapter_set.all() , you can set what this
> attribute is named by doin
The first way is the correct way, to get all the chapters for a given
book you would do book_obj.chapter_set.all() , you can set what this
attribute is named by doing ForeignKey(Chapter,
related_name='this_thing').
On May 9, 11:08 am, Mike Chambers <[EMAIL PROTECTED]> wrote:
> I am working on an
I am working on an app to host some books online. I cant figure out the
best way to represent a one to many relationship.
Basically, a Book has multiple Chapters, but a Chapter can only be in
one book.
Looking at the docs, this seems to be the way to represent this:
--
class Book(models.
4 matches
Mail list logo