Monday, August 8, 2011

ManyToMany to_field through and db_table questions

Can anyone tell me if to_field is valid in this context and what is the
distinction between through and db_table? ...

class Sections(models.Model):
""" intermediary table for Document recursive m2m """
document = models.ForeignKey(Document, to_field='ancestor')
section = models.ForeignKey(Document, to_field='ancestor')
comment = models.TextField()

class Document(models.Model):
ancestor = models.IntegerField()
sections = models.ManyToManyField('self',
symmetrical=False,
through=Sections,
db_table=Sections,
related_name='Comprise')

... where 'ancestor' is a surrogate key which survives in descendant
documents - such being both newer revisions of the same document and
other documents more or less based on the ancestral document.

I also wonder how I might have a m2m recursive relationship between
documents without specifying an intermediary table - iow if the comment
column was not needed - is it OK to specify to_field='ancestor' in the
Document model?

Thanks for any help

Mike

--
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