Version 2 (modified by oubiwann, 19 years ago) ( diff )

--

CookBook - DataModel

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):
    fields = (
        meta.CharField('short_name', maxlength=30),
        meta.CharField('title', maxlength=100),
    )

    def __repr__(self):
        return self.title

    admin = meta.Admin()

class Paragraph(meta.Model):
    fields = (
        meta.ForeignKey(Document, edit_inline=True, num_in_admin=3, num_extra_on_change=1),),
        meta.TextField('content'),
    )

    def __repr__(self):
        return self.headline
Note: See TracWiki for help on using the wiki.
Back to Top