Skip to content
Snippets Groups Projects

Django News Box

This django app is a toolbox to easily setup news in your projects.

Features

  • easy custom fields
  • optional SEO fields
  • optional publication period
  • optional i18n support via parler
  • optional django-cms support

Installation

Add newsbox to your INSTALLED_APPS. If you need newsbox_cms and/or newsbox_i18n, add those too.

django integration

models.py

django CMS integration

models.py

For basic news, you just have to inherit from NewsboxCMSBase :

from newsbox_cms.models import NewsboxCMSBase

class News(NewsboxCMSBase):
    
    class Meta:
        newsbox_detail_url_name = "news_detail"  # optional

You can create news with i18n via I18N. Inherit first from NewsboxI18NBase, then from NewsboxCMSBase :

from newsbox_cms.models import NewsboxCMSBase
from newsbox_i18n.models import NewsboxI18NBase

class News(NewsboxI18NBase, NewsboxCMSBase):
    
    class Meta:
        newsbox_detail_url_name = "news_detail"  # optional

If you need SEO fields and/or expiration fields, inherit from NewsboxSEOBase and/or NewsboxExpiredBase :

from newsbox.models import NewsboxSEOBase, NewsboxExpiredBase
from newsbox_cms.models import NewsboxCMSBase

class News(NewsboxCMSBase, NewsboxSEOBase, NewsboxExpiredBase):
    
    class Meta:
        newsbox_detail_url_name = "news_detail"  # optional

For the plugin, you just have to inherit from NewsboxPluginBase :

from newsbox_cms.models import NewsboxPluginBase

class NewsPlugin(NewsboxPluginBase):
    newsbox_model = News

cms_app.py

Nothing special here. Just create your basic cms app :

from cms.app_base import CMSApp
from cms.apphook_pool import apphook_pool

class NewsApphook(CMSApp):
    name = _("News")
    urls = ["myproject.news_urls"]

apphook_pool.register(NewsApphook)

news_urls.py

This file is used by your CMS App. You have to specify the news detail URL and set the template and the model to use for this url.

from django.conf.urls import patterns, url
from newsbox.views import NewsboxDetailView
from .models import News

urlpatterns = patterns(
    '',
    url(
        r'^(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d{2})/(?P<slug>[0-9a-zA-Z_-]+)/$', 
        NewsboxDetailView.as_view(
            template_name="myproject/news_detail.html",
            model=News,),
        name='news_detail'),
)

cms_plugin.py

You just have to inherit from NewsboxPluginBase to create a plugin to manage your news.

from cms.plugin_pool import plugin_pool
from newsbox_cms.cms_plugins import NewsboxPluginBase
from .models import NewsPlugin as NewsPluginModel


class NewsPlugin(NewsboxPluginBase):
    model = NewsPluginModel

plugin_pool.register_plugin(NewsPlugin)