A simple Django app to add draft/publish capabilities to your models.
Project description
# Django-Publishable
Django library that add to your models the draft/publish features.
## 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
```
Django library that add to your models the draft/publish features.
## 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
```
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Close
Hashes for django_publishable-0.1.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1cadd39b412bce25d4ea067bfb1a904736a3e6857c74fe1726830af1dc3bf0e0 |
|
MD5 | 3c6014c8ebcf034855ebe048aeda3121 |
|
BLAKE2b-256 | 250e16508c90566e2e5cc189ee84b4fa755e0a066d079d90d49496bfc74fb32e |