FeinCMS core

General functions

feincms.ensure_completely_loaded(force=False)

This method ensures all models are completely loaded

FeinCMS requires Django to be completely initialized before proceeding, because of the extension mechanism and the dynamically created content types.

For more informations, have a look at issue #23 on github: http://github.com/feincms/feincms/issues#issue/23

Base models

This is the core of FeinCMS

All models defined here are abstract, which means no tables are created in the feincms_ namespace.

class feincms.models.Base(*args, **kwargs)

This is the base class for your CMS models. It knows how to create and manage content types.

Base.content

Instantiate and return a ContentProxy. You can use your own custom ContentProxy by assigning a different class to the content_proxy_class member variable.

Base.content_proxy_class

alias of ContentProxy

classmethod Base.content_type_for(model)

Return the concrete content type for an abstract content type:

from feincms.content.video.models import VideoContent concrete_type = Page.content_type_for(VideoContent)

Base.copy_content_from(obj)

Copy all content blocks over to another CMS base object. (Must be of the same type, but this is not enforced. It will crash if you try to copy content from another CMS base type.)

classmethod Base.create_content_type(model, regions=None, class_name=None, **kwargs)

This is the method you’ll use to create concrete content types.

If the CMS base class is page.models.Page, its database table will be page_page. A concrete content type which is created from ImageContent will use page_page_imagecontent as its table.

If you want a content type only available in a subset of regions, you can pass a list/tuple of region keys as regions. The content type will only appear in the corresponding tabs in the item editor.

If you use two content types with the same name in the same module, name clashes will happen and the content type created first will shadow all subsequent content types. You can work around it by specifying the content type class name using the class_name argument. Please note that this will have an effect on the entries in django_content_type, on related_name and on the table name used and should therefore not be changed after running syncdb for the first time.

Name clashes will also happen if a content type has defined a relationship and you try to register that content type to more than one Base model (in different modules). Django will raise an error when it tries to create the backward relationship. The solution to that problem is, as shown above, to specify the content type class name with the class_name argument.

If you register a content type to more than one Base class, it is recommended to always specify a class_name when registering it a second time.

You can pass additional keyword arguments to this factory function. These keyword arguments will be passed on to the concrete content type, provided that it has a initialize_type classmethod. This is used f.e. in MediaFileContent to pass a set of possible media positions (f.e. left, right, centered) through to the content type.

classmethod Base.register_regions(*regions)

Register a list of regions. Only use this if you do not want to use multiple templates with this model (read: not use register_templates):

BlogEntry.register_regions(
    ('main', _('Main content area')),
    )
classmethod Base.register_templates(*templates)

Register templates and add a template_key field to the model for saving the selected template:

Page.register_templates({
    'key': 'base',
    'title': _('Standard template'),
    'path': 'feincms_base.html',
    'regions': (
        ('main', _('Main content area')),
        ('sidebar', _('Sidebar'), 'inherited'),
        ),
    }, {
    'key': '2col',
    'title': _('Template with two columns'),
    'path': 'feincms_2col.html',
    'regions': (
        ('col1', _('Column one')),
        ('col2', _('Column two')),
        ('sidebar', _('Sidebar'), 'inherited'),
        ),
    })
Base.replace_content_with(obj)

Replace the content of the current object with content of another.

Deletes all content blocks and calls copy_content_from afterwards.

class feincms.models.ContentProxy(item)

The ContentProxy is responsible for loading the content blocks for all regions (including content blocks in inherited regions) and assembling media definitions.

The content inside a region can be fetched using attribute access with the region key. This is achieved through a custom __getattr__ implementation.

ContentProxy.all_of_type(type_or_tuple)

Returns all content type instances belonging to the type or types passed. If you want to filter for several types at the same time, type must be a tuple.

The content type instances are sorted by their ordering value, but that isn’t necessarily meaningful if the same content type exists in different regions.

ContentProxy.media

Collect the media files of all content types of the current object

class feincms.models.Region(key, title, *args)

This class represents a region inside a template. Example regions might be ‘main’ and ‘sidebar’.

Region.content_types

Returns a list of content types registered for this region as a list of (content type key, beautified content type name) tuples

class feincms.models.Template(title, path, regions, key=None, preview_image=None)

A template is a standard Django template which is used to render a CMS object, most commonly a page.

feincms.models.create_base_model(inherit_from=<class 'django.db.models.base.Model'>)

This method can be used to create a FeinCMS base model inheriting from your own custom subclass (f.e. extend MPTTModel). The default is to extend django.db.models.Model.

Table Of Contents

Previous topic

FeinCMS Deprecation Timeline

Next topic

Admin classes

This Page