Hi Tim!

On Sat, 5 Mar 2011 06:05:51 -0800 (PST), Tim <jtim.arn...@gmail.com> wrote:
> For me that looks a little complex. The 'sequence' doesn't really
> belong to the Chapter or the Book, but to their relationship. A
> Chapter may have one sequence number when part of Book A, and another
> for Book B.

That's a classic example for a many-to-many relationship with additional
data.


class Book(models.Model):
      (...)

class Chapter(models.Model):
      (...)
      book = models.ManyToManyField(through="BookChapter")

class BookChapter(models.Model):
      (...)
      sequence = models.IntegerField

You can find more info about the `through` parameter at:

http://docs.djangoproject.com/en/dev/ref/models/fields/#django.db.models.ManyToManyField.through


Hope that helps,

Michael

-- 
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+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to