The scaffold API

Model methods

The following methods are provided by scaffold.models.BaseSection:

class scaffold.models.BaseSection(*args, **kwargs)

An abstract model of a section or subsection. This class provides a base level of functionality that should serve as scaffold for a custom section object.

get_associated_content(only=[], sort_key=None)

This method returns an aggregation of all content that’s associated with a section, including subsections, and other objects related via any type of foreign key. To restrict the types of objetcs that are returned from foreign-key relationships, the only argument takes a list of items with the signature:

{app name}.{model name}

For example, if you wanted to retrieve a list of all subsections and associated articles only, you could do the following:

section = Section.objects.all()[0]

Furthermore, if all objects have a commone sort key, you can specify that with the sort_key parameter. So, since sections have an ‘order’ field, if articles had that field as well, you could do the following:

section = Section.objects.all()[0]

...and the list returned would be sorted by the ‘order’ field.


Returns the first non-empty instance of the given field in the sections tree. Will crawl from leaf to root, returning None if no non-empty field is encountered.

A method to access content associated with a section via a foreign-key relationship of any type. This includes content that’s attached via a simple foreign key relationship, and content that’s attached via a generic foreign key (for example, through a subclass of the SectionItem model).

This method returns a list of tuples:

(object, app name, model name, relationship_type)

To sort associated content, pass a list of sort fields in via the sort_fields argument. For example, let’s say we have two types of content we know could be attached to a section: articles and profiles Articles should be sorted by their ‘headline’ field, while profiles should be sorted by their ‘title’ field. We would call our method thusly:

section = Section.objects.all()[0]
section.get_related_content(sort_fields=['title', 'headline'])

This will create a common sort key on all assciated objects based on the first of these fields that are present on the object, then sort the entire set based on that sort key. (NB: This key is temporary and is removed from the items before they are returned.)

If ‘infer_sort’ is True, this will override the sort_fields options and select each content type’s sort field based on the first item in the ‘ordering’ property of it’s Meta class. Obviously, infer_sort will only work if the types of fields that are being compared are the same.


This method return all subsections of the current section.


A property that returns the string ‘section’ if the section is at the root of the tree, ‘subsection’ otherwise.


The sections application contains the following views.


Use the middleware if you need access to the section outside the view context.

class scaffold.middleware.SectionsMiddleware

Middleware that stores the current section (if any) in the thread of the currently executing request


Determine the section from the request and store it in the currently executing thread where anyone can grab it (remember, in Django, there’s one request per thread).


Convenience function to get the current section from the thread of the currently executing request, assuming there is one. If not, returns None. NB: Make sure that the SectionsMiddleware is enabled before calling this function. If it is not enabled, this function will raise a MiddlewareNotUsed exception.


NB: lookup_from may either be an HTTP request, or a string representing an integer.

scaffold.middleware.reset_section_path_map(sender, **kwargs)