本文整理汇总了Python中qa.models.Question.add_follower方法的典型用法代码示例。如果您正苦于以下问题:Python Question.add_follower方法的具体用法?Python Question.add_follower怎么用?Python Question.add_follower使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类qa.models.Question
的用法示例。
在下文中一共展示了Question.add_follower方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: ask_question
# 需要导入模块: from qa.models import Question [as 别名]
# 或者: from qa.models.Question import add_follower [as 别名]
def ask_question(request):
if not request.user.is_authenticated():
return redirect('/')
else:
hut_slug = request.POST['hut']
hut = Course.objects.get(slug=hut_slug)
title = request.POST['title']
if len(title) == 0:
return ask(request, error='You need to enter a title.', hut_slug=hut_slug)
content = request.POST['content']
if len(content) == 0:
return ask(request, error='You need to enter some content to your question.', title=title, hut_slug=hut_slug)
tags = request.POST['tags'].strip().replace(',', '').replace('#', '').split(' ')
if len(tags) == 1 and len(tags[0]) == 0:
return ask(request, error='You need to enter some tags.', title=title, content=content, hut_slug=hut_slug)
question = Question(title=title, content=content, author=request.user, course=hut)
question.save()
question.add_tag(hut.slug)
question.add_tag(State.CURRENT_QUARTER)
question.add_follower(request.user)
for tag in tags:
question.add_tag(tag)
if hut.has_approved(request.user):
question.approved = True
question.save()
message_subscribers(hut, question, request.user)
return redirect('/question/%d' % question.id)
return redirect('/?msg=moderation')