一个简单的django应用程序,可以向模型添加草稿/发布功能。
django-publishable的Python项目详细描述
#Django可出版?
[![PyPI版本](https://badge.fury.io/py/django publishable.svg)](https://badge.fury.io/py/django-publishable)[![Circleci](https://circleci.com/gh/ilyes-hammadi/django-publishable.svg?style=svg)“(https://circleci.com/gh/ilyes hammadi/django可发布)
django可发布什么?
django库为您的模型添加了草稿/发布功能。
将“可发布”添加到已安装的应用程序设置中,如下所示:
`` python
已安装的应用程序=[
…
'可发布',
]
```
2运行“python manage.py migrate”创建可发布的模型。
3.尝试将其与模型复制:
``python
from django.db import models
from publishable.models import publishablePublisher
Publisher负责触发其包含的publish all drafts
类用户(Publisher):
传递
abstract=True
def broadcast_need_to_published(self):
“
”此函数将返回一个草稿实例,然后由您选择您的发布者并将其添加到草稿中self).broadcast_need_to_published()
chatbot,u=User.objects.get_or_create(pk=1)
chatbot.add_draft(draft)
models.charfield(最大长度=255)
content=models.textfield()
highlighted_comment=models.foreignkey('comment',related_name='highlighted_comment',空=真)
类注释(可发布):
内容=models.charfield(最大长度=255)
````
4。默认情况下,现在您的所有模型都会将更改存储到草稿中
``python
;添加更改并发布一个模型
>;>a=article.objects.create()
>;>a.title=“foo”
>;>a.publish()
>;>a.published.title
foo
publisher
>;>;a.title=“boo”
>;>;a.save()
>;>;a.published.title
foo
>;>;user=user.objects.get(pk=1)
>;>;user.publish()
user.publishing_status
published
```
在“with”中执行的每个操作都将针对模型的已发布版本但是,请小心不要对“published”做任何更改,您只应读取数据,插入数据时应以“draft”为目标。
``python
>;>gt;从publisheble.context\u managers导入publishedcontextmanager
>;>a=article.objects.create(title=“foo”)
>;>a.publish()
>;>a.title=“boo”
>;>;a.save()
>;>;使用PublishedContextManager():
打印(a.title)
foo
>;>;打印(a.title)
boo
````
[![PyPI版本](https://badge.fury.io/py/django publishable.svg)](https://badge.fury.io/py/django-publishable)[![Circleci](https://circleci.com/gh/ilyes-hammadi/django-publishable.svg?style=svg)“(https://circleci.com/gh/ilyes hammadi/django可发布)
django可发布什么?
django库为您的模型添加了草稿/发布功能。
将“可发布”添加到已安装的应用程序设置中,如下所示:
`` python
已安装的应用程序=[
…
'可发布',
]
```
2运行“python manage.py migrate”创建可发布的模型。
3.尝试将其与模型复制:
``python
from django.db import models
from publishable.models import publishablePublisher
Publisher负责触发其包含的publish all drafts
类用户(Publisher):
传递
abstract=True
def broadcast_need_to_published(self):
“
”此函数将返回一个草稿实例,然后由您选择您的发布者并将其添加到草稿中self).broadcast_need_to_published()
chatbot,u=User.objects.get_or_create(pk=1)
chatbot.add_draft(draft)
models.charfield(最大长度=255)
content=models.textfield()
highlighted_comment=models.foreignkey('comment',related_name='highlighted_comment',空=真)
类注释(可发布):
内容=models.charfield(最大长度=255)
````
4。默认情况下,现在您的所有模型都会将更改存储到草稿中
``python
;添加更改并发布一个模型
>;>a=article.objects.create()
>;>a.title=“foo”
>;>a.publish()
>;>a.published.title
foo
publisher
>;>;a.title=“boo”
>;>;a.save()
>;>;a.published.title
foo
>;>;user=user.objects.get(pk=1)
>;>;user.publish()
user.publishing_status
published
```
在“with”中执行的每个操作都将针对模型的已发布版本但是,请小心不要对“published”做任何更改,您只应读取数据,插入数据时应以“draft”为目标。
``python
>;>gt;从publisheble.context\u managers导入publishedcontextmanager
>;>a=article.objects.create(title=“foo”)
>;>a.publish()
>;>a.title=“boo”
>;>;a.save()
>;>;使用PublishedContextManager():
打印(a.title)
foo
>;>;打印(a.title)
boo
````