Using the contrib.blog module

Complete blog system with posts, featured posts, and versioning.

Installation

INSTALLED_APPS = [
    "djangocms_custom_content",
    "djangocms_custom_content.contrib.blog",
]
python manage.py migrate

Models

BlogPost - Groups all language versions of a blog post. Declares two grouper-to-grouper relations via RelationField: authors (ordered, to people.Person) and categories (to categories.FlatCategory).

BlogPostContent - Language-specific post content

Content fields: title, slug, excerpt, body, is_featured, published_at, language

Usage

from djangocms_custom_content.contrib.blog.models import BlogPost, BlogPostContent

post = BlogPost.objects.create()
BlogPostContent.objects.create(
    post=post,
    language="en",
    title="My First Post",
    slug="my-first-post",
    excerpt="Short summary...",
    body="Full content...",
)

# Access by language
english_version = post.get_content(language="en")

# Get featured posts
featured = BlogPostContent.objects.filter(is_featured=True)

Plugins

  • BlogPostTeaserPlugin (“Blog post”) - Display a single selected post

  • BlogPostListPlugin (“Blog post list”, model BlogPostList) - A paginated index of published posts, optionally featured-only

The list plugin is the worked example of filling an app hook’s root page, which the framework deliberately leaves to you rather than generating a list view (see The root page is yours: listing content). Three things in it are worth copying into your own list plugin:

  • cache = False, because the output depends on the page query parameter;

  • a page parameter namespaced by the plugin’s primary key (page-12), so two lists on one page paginate independently;

  • an out-of-range page falling back to the last page rather than raising a 404 from inside a plugin.

Admin

BlogPostAdmin is a GrouperModelAdmin (see Register the grouper admin) with content__-prefixed list display and search, and it renders the authors and categories relations as autocomplete widgets.

What this app demonstrates

The blog is the reference example for the relations system: it declares both an ordered relation (authors → Person, drag-sortable in the admin) and an unordered one (categories → FlatCategory), on a content model that is per-language versioned (it has a language field) and frontend-editable.

See Also