|Version 8 (modified by verbosus, 11 years ago) (diff)|
CookBook - Data Model
Multiple Levels and Multiple Components
There are times when you have data/content that has many-to-one relationships. This is very easy to accomodate, just as this example demonstrates. Here is code similar to that of the example:
from django.core import meta class Document(meta.Model): short_name = meta.CharField(maxlength=30) title = meta.CharField(maxlength=100) def __repr__(self): return self.title class META: admin = meta.Admin() class Paragraph(meta.Model): document = meta.ForeignKey( Document, edit_inline=True, num_in_admin=3, num_extra_on_change=1 ) content = meta.TextField() def __repr__(self): return self.headline
This is fantastic. It's convenient. But... what if we have more than just two "levels"? What if our document data is divided into two types of data, say "summary" and "details"? And what if each of these views then has potentially multiple paragraphs?
Stay tuned; more to come...