Reference¶
-
wagtailnews.decorators.
newsindex
(cls)[source]¶ Register a
NewsIndexMixin
page. News indexes need to be registered before news items can be managed through the admin.@newsindex class NewsIndex(NewsIndexMixin, Page): newsitem_model = NewsItem
News items¶
Fields¶
-
AbstractNewsItem.
date
¶ A
DateTimeField
that records the published date of this news item. It is automatically set when the news item is created. You can add it to theAbstractNewsItem.panels
list if you want editors to be able to customise the date. If set in the future, the post will not appear on the front end.
-
AbstractNewsItem.
live
¶ A
BooleanField
that indicates if this news item is live. A live news item might have unpublished drafts.
Attributes¶
-
AbstractNewsItem.
template
¶ The template to use for this news item. Defaults to
app_label/model_name.html
.
Methods¶
-
AbstractNewsItem.
get_nice_url
()[source]¶ Make a slug to put in the URL. News items are fetched using their ID, which is also embedded in the URL, this slug just makes the URLs nicer. The slug does not need to be unique. By default, it is generated from
slugify(str(self))
.
-
AbstractNewsItem.
get_template
(request)[source]¶ Get the template for this news item. See also
AbstractNewsItem.template
.
-
AbstractNewsItem.
get_context
(request, *args, **kwargs)[source]¶ Build a context dictionary for the template. The default implementation gets the context from the news index, and adds the news item as
newsitem
.
-
AbstractNewsItem.
url_suffix
()[source]¶ Return the URL of this news item relative to the news index.
>>> newsitem.url_suffix() '2016/08/11/1234-my-news-item/'
See also
AbstractNewsItem.get_nice_url()
.
News index¶
Attributes¶
-
NewsIndexMixin.
newsitem_model
¶ The news item model to use for this news index. The news item model must be a subclass of
AbstractNewsItem
. This can either be the name of the model as a string, such as ‘NewsItem’ or ‘myapp.NewsItem’, or the actual news item class.
-
NewsIndexMixin.
feed_class
¶ The
Feed
class to use to create the RSS feed. See RSS Feed for more details.
-
NewsIndexMixin.
subpage_types
¶ Defaults to an empty list. News indexes with subpages are not supported.
Methods¶
-
classmethod
NewsIndexMixin.
get_newsitem_model
()[source]¶ Get the news item model for this news index. See
NewsIndexMixin.newsitem_model
.
Routes¶
The functionality of news indexes come from Wagtail’s RoutablePageMixin. The following routes are defined:
index
The root url which shows all news items.
>>> newsindex.reverse_subpage('index') ''
year
Displays all news items from a year.
>>> newsindex.reverse_subpage('year', kwargs={'year': '2016'}) '2016/'
month
Displays all news items from a month.
>>> newsindex.reverse_subpage('month', kwargs={'year': '2016', 'month': '08'}) '2016/08/'
day
Displays all news items from a day.
>>> newsindex.reverse_subpage('day', kwargs={'year': '2016', 'month': '08', 'day': '15'}) '2016/08/15/'
post
Shows a single news item.
>>> newsindex.reverse_subpage('post', kwargs={ ... 'year': '2016', 'month': '08', 'day': '15', ... 'pk': newsitem.pk, 'slug': newsitem.get_nice_url()}) '2016/08/15/1234-my-news-item/'
See also
AbstractNewsItem.get_nice_url()
andAbstractNewsItem.url_suffix()
.feed
Show the RSS feed.
>>> newsindex.reverse_subpage('rss') 'rss/'
See also RSS Feed.