django-pubtools is a helper library for creating publishable django models.
[](https://circleci.com/gh/gregplaysguitar/django-pubtools)
[](https://codecov.io/gh/gregplaysguitar/django-pubtools)
[](https://pypi.python.org/pypi/django-pubtools/)
## 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
models.py:
```python
from django.db import models
import pubtools.models
class Article(pubtools.models.AbstractPublishableModel):
title = models.CharField(max_length=100)
```
views.py:
```python
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)
```
admin.py:
```python
from django.contrib import admin
from baseclasses.admin import PublishableModelAdminMixin
from .models import Article
@admin.register(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
[](https://circleci.com/gh/gregplaysguitar/django-pubtools)
[](https://codecov.io/gh/gregplaysguitar/django-pubtools)
[](https://pypi.python.org/pypi/django-pubtools/)
## 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
models.py:
```python
from django.db import models
import pubtools.models
class Article(pubtools.models.AbstractPublishableModel):
title = models.CharField(max_length=100)
```
views.py:
```python
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)
```
admin.py:
```python
from django.contrib import admin
from baseclasses.admin import PublishableModelAdminMixin
from .models import Article
@admin.register(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
Metadata
Release files for django-pubtools 2.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| django-pubtools-2.0.4.tar.gz | 6.4 kB | Without provenance | Details |
Release files / django-pubtools-2.0.4.tar.gz
| Download URL | django-pubtools-2.0.4.tar.gz |
|---|---|
| Size | 6.4 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c7dacdbc91c73275287ee7d0de8833928c4cc3f54cf2ffc67e52240be5cb6517
|
|
BLAKE2b-256 checksum How to use checksums |
1ee11f7c87d9016c75ec2555e26483949bb7b6ed450f3d3076133369a614e449
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
Security for django-pubtools 2.0.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.