本文整理汇总了Python中models.Article.category方法的典型用法代码示例。如果您正苦于以下问题:Python Article.category方法的具体用法?Python Article.category怎么用?Python Article.category使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Article
的用法示例。
在下文中一共展示了Article.category方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __save_blog
# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import category [as 别名]
def __save_blog(title, abstract, body, category_id, tag_names, article_id=None):
tags = []
for tag_name in tag_names.split(','):
tag, is_create = Tag.objects.get_or_create(name=tag_name)
tags.append(tag)
category = Category.objects.filter(id=category_id)[0]
if article_id is None:
article = Article(title=title, abstract=abstract, body=body, category=category)
else:
article = Article.objects.filter(id=article_id)[0]
article.title = title
article.abstract = abstract
article.body = body
article.category = category
article.save()
print dir(article)
article.tag.clear()
article.tag.add(*tags)
return article.id
示例2: post
# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import category [as 别名]
def post(self, request, *args, **kwargs):
if request.session.get('account_id', None) is None:
return HttpResponseRedirect('/account/login')
d = request.POST.dict()
i = Article()
account_id = request.session['account_id']
i.account_id = str(account_id)
i.username = request.session['username']
tag = d.get('tag', None)
if tag != '':
if tag[-1] == ';':
tag = tag[:-1]
i.tag = tag.split(';')
i.category = int(d['category'])
i.head_image = d.get('head_image', None)
i.title = d['title']
i.content = d['content']
i.status = 1
i.save()
return HttpResponseRedirect('/blog')