[](https://badge.fury.io/py/django-publishable) [](https://circleci.com/gh/Ilyes-Hammadi/django-publishable)
## What is Django-Publishable?
Django library that add to your models the draft/publish features.
## Instalation
```shell
$ pip install django-publishable
```
## Quick start
1. Add "publishable" to your INSTALLED_APPS setting like this::
```python
INSTALLED_APPS = [
...
'publishable',
]
```
2. Run `python manage.py migrate` to create the publishable models.
3. Try to replicate this with your models:
```python
from django.db import models
from publishable.models import Publishable, Publisher
# A Publisher is responsible for triggering
# the publish all drafts that he contains
class User(Publisher):
pass
# Overdide the Publishable to implement the logic
# of broadcast_need_to_published
class MyPublishable(Publishable):
class Meta:
abstract = True
def broadcast_need_to_published(self):
"""
This function will return a Draft instance
then it's up to you select your Publisher
and add it to it's draft
"""
draft = super(MyPublishable, self).broadcast_need_to_published()
chatbot, _ = User.objects.get_or_create(pk=1)
chatbot.add_draft(draft)
# After setting up your Publishable
# then inherit from it into the model that you need to receie
# draft/publish features
class Article(MyPublishable):
title = models.CharField(max_length=255)
content = models.TextField()
comments = models.ManyToManyField('Comment', related_name='comments')
highlighted_comment = models.ForeignKey('Comment', related_name='highlighted_comment', null=True)
class Comment(MyPublishable):
content = models.CharField(max_length=255)
```
4. By default now all your model will store changes into the draft
```python
# Add changes and publish one model
>>> a = Article.objects.create()
>>> a.title = "foo"
>>> a.publish()
>>> a.published.title
foo
# Let's add changes and publish using a publisher
>>> a.title = "boo"
>>> a.save()
>>> a.published.title
foo
>>> user = User.objects.get(pk=1)
>>> user.publish()
# You can track the status of the publishing process
>>> user.publishing_status
PUBLISHED
```
## Using the Context Manager
In order to keep your code clean and avoid replication of code by doing `article.published` all the time, you can use the `PublishedContextManager`. Every operation that you do inside the `with` will target the published version of the model. But be carful do not do any changes to the `published`, you're only supposed to read data, inserting the data should target the `draft`.
```python
>>> from publishable.context_managers import PublishedContextManager
>>> a = Article.objects.create(title="foo")
>>> a.publish()
>>> a.title = "boo"
>>> a.save()
>>> with PublishedContextManager():
print(a.title)
foo
>>> print(a.title)
boo
```
Metadata
Release files for django-publishable 0.1.13
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 | Actions |
|---|---|---|---|---|
| django-publishable-0.1.13.tar.gz | 10.3 kB | Without provenance | Details for django-publishable-0.1.13.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| django_publishable-0.1.13-py3-none-any.whl | Python 3 | none | any | Details for django_publishable-0.1.13-py3-none-any.whl |
Total release size: 22.4 kB
Release files / django-publishable-0.1.13.tar.gz
| Download URL | django-publishable-0.1.13.tar.gz |
|---|---|
| Size | 10.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
69e5dd50717da8b0e5d9fd279c024d244c4685b338c38b9f921c86d66a50bb67
|
|
BLAKE2b-256 checksum How to use checksums |
58ae8176859e231a1ffe4d785d8718de143a268806ff9edbd57b057d4a4fd9f4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.7.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.6.4
|
Release files / django_publishable-0.1.13-py3-none-any.whl
| Download URL | django_publishable-0.1.13-py3-none-any.whl |
|---|---|
| Size | 12.1 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
9d00c211ba3b1e71ccf9604cdfc74e9494a18ff60bbf56baa8fd94ec6bb3c999
|
|
BLAKE2b-256 checksum How to use checksums |
72ae4a5770ae98faa8c146e024c5179a533476c2450e402d1b7abee86aa5b58b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/1.12.1 pkginfo/1.5.0.1 requests/2.21.0 setuptools/40.7.0 requests-toolbelt/0.8.0 tqdm/4.30.0 CPython/3.6.4
|
Security for django-publishable 0.1.13
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.
To learn more about protecting yourself from malicious actors, visit our package security documentation.