本文整理汇总了Python中models.Article.create方法的典型用法代码示例。如果您正苦于以下问题:Python Article.create方法的具体用法?Python Article.create怎么用?Python Article.create使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Article
的用法示例。
在下文中一共展示了Article.create方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: store
# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import create [as 别名]
def store(self, topic_name, article_entry_list):
"""Stores the article entries in the database.
:param topic_name The name of the topic
:param article_entry_list The list of entries of this topic
"""
try:
# Try to retrieve the topic to see if it exists already
topic = Topic.get(Topic.name == topic_name)
except Topic.DoesNotExist:
# If not, create it
topic = Topic.create(name=topic_name)
# Go through all the articles in this topic
for article_entry in article_entry_list:
article_name = article_entry.subject
# If there is no subject, it means the article is corrupted
# therefore we skip it
if not article_name:
continue
# Create the files with the content
# Overwrite existing files
try:
Article.create(topic=topic, subject=article_name,
body=article_entry.body)
except Article.DoesNotExist:
pass
示例2: process_item
# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import create [as 别名]
def process_item(self, item, spider):
try:
rows = Article.select().where(Article.id == int(item['url'].split('/')[-1]))
for row in rows:
if row:
Article.update(title=item['title'], url=item['url'], read_count=item['read_count'],
comment_count=item['comment_count'], update_time=datetime.datetime.now())\
.where(Article.id == int(item['url'].split('/')[-1])).execute()
else:
Article.create(id=int(item['url'].split('/')[-1]), title=item['title'], url=item['url'], read_count=item['read_count'],
comment_count=item['comment_count'], create_time=datetime.datetime.now(),
update_time=datetime.datetime.now())
except Exception, e:
print e
示例3: documents_generate
# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import create [as 别名]
def documents_generate(request):
if request.method == 'POST':
data = json.loads(request.body)
a = Article.create(json=data["article"])
docs = Document.fromJson(data["documents"])
file_name = process_documents(docs, a)
archive = Archieve.create(file_name)
return JsonResponse({"url": archive.identifier})
示例4: POST
# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import create [as 别名]
def POST(self):
if session.login == False:
return bad_request('请先登录')
data = web.data()
data = json.loads(data)
title = data.get('title')
content = data.get('content')
user_id = session.user.id
article_data = {
'title' : title,
'created_time' : time.time(),
'user_id' : user_id,
'content' : content,
'serial_id' : 0,
'zan' : 0
}
try:
article_id = Article.create(**article_data)
except Exception,e:
return bad_request('你已创建过该名称!')