Skip to main content
Help us improve PyPI by participating in user testing. All experience levels needed!

A set of reusable base classes and helpers for django

Project description

django-pubtools is a helper library for creating publishable django models.

[![Circle CI](](
[![Latest Version](](

## Overview

Extend the `AbstractPublishableModel` class to create a publishable model class.

- Publishable content can be in either draft, preview, or published status.
- Draft content may be previewed on the site by a logged-in staff member
- Preview content may be previewed publicly, via a special url

## Installation

pip install django-pubtools

## Example implementation

from django.db import models
import pubtools.models

class Article(pubtools.models.AbstractPublishableModel):
title = models.CharField(max_length=100)

from django.http import HttpResponse
from .models import Article

def article(request, id):
# pass the request to enable staff preview
articles = Article.objects.published(request)
article = articles.get(id=id)
return HttpResponse(article.title)

from django.contrib import admin
from baseclasses.admin import PublishableModelAdminMixin

from .models import Article

class ArticleAdmin(PublishableModelAdminMixin, admin.ModelAdmin):
list_display = ['title']

## Reference

### `pubtools.models.AbstractPublishableModel`

##### Model fields

- `created` (datetime, set on creation)
- `last_updated` (datetime, updated on save)
- `pub_date` (date)
- `pub_status` (one of draft, review or published)

##### Model methods

- `published` (property) return True if the instance is published
- `get_prev_published(qs=None, loop=False)` get previous published instance
- `get_next_published(qs=None, loop=False)` get next published instance

### `pubtools.models.PublishableModelQuerySet`

##### Manager/queryset methods

- `published(self, request=None)` If request is passed, and a preview status
flag is in request.GET, then check if the user is a staff member, and
return objects with the requested status if so. Otherwise, return only
published objects.

### `pubtools.admin.PublishableModelAdminMixin`

- Overrides `view_on_site` to add a flag to urls for draft/preview content.
- Adds a "Publish selected" action to the admin

Project details

Release history Release notifications

This version
History Node


History Node


History Node


History Node


History Node


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Filename, size & hash SHA256 hash help File type Python version Upload date
django-pubtools-2.0.4.tar.gz (6.4 kB) Copy SHA256 hash SHA256 Source None Dec 5, 2017

Supported by

Elastic Elastic Search Pingdom Pingdom Monitoring Google Google BigQuery Sentry Sentry Error logging CloudAMQP CloudAMQP RabbitMQ AWS AWS Cloud computing Fastly Fastly CDN DigiCert DigiCert EV certificate StatusPage StatusPage Status page