Pages and Sections#

Overview#

Pages and sections are the basic building blocks of your website. Pages define regions in which sections can be placed. And sections can be any kind of content you want to see on your website.

Pages and sections are defined by subclassing the Page and Section model:

from simple_page.models import Page, Section

class FancyPage(Page):
    REGIONS = [
        ('main', 'Main Region'),
        ('sidebar', 'Sidebar'),
        ('footer', 'Footer'),
    ]

    class Meta:
        proxy = True


class FancySection(Section):
    title = models.CharField(max_length=255, blank=True)
    text = models.TextField(blank=True)

With those two models you are able to build a simple website.

Api Reference#

class simple_page.models.Page(*args, **kwargs)#

Bases: MPTTModel

Base model for all pages.

The only thing a subclass has to do is to setup its regions. Since the database layout is fully functional, you may define your own page model as a proxy if you do not want to provide additional fields.

Sections associated with a page are accessible by their region. Use the region’s name to get a queryset of sections belonging to that region.

The page model is tree structured by django-mptt.

REGIONS = []#

REGIONS must be set by subclasses as a list of tuples holding the region’s name and its title. Something like:

REGIONS = [
    ('main', 'Main Region'),
    ('sidebar', 'Sidebar'),
    ('footer', 'Footer'),
]
classmethod get_regions()#

Return the regions for this page. This method can be customized by child classes to return different regions.

resolve_obj()#

Return the instance of the child class.

class simple_page.models.Section(*args, **kwargs)#

Bases: Model

Base model for what ever content you want to see on your website. It does not has any fields by its own but can be equipped by sublcasses.

Sections are related to pages via a many-to-many relationship that holds the region in which a section should be rendered and an index field to make the sections orderable whithin that region.

objects = <model_utils.managers.InheritanceManager object>#

We use the InheritanceManager to provide a simple api to access child class objects.

class simple_page.models.PageSection(*args, **kwargs)#

Bases: Model

PageSection is the intermediate model for the many-to-many relationship between pages and sections. It holds the region in which a section should be rendered and an index field to make sections orderable whithin that region.