本文整理汇总了Python中forums.models.Post.get_absolute_url方法的典型用法代码示例。如果您正苦于以下问题:Python Post.get_absolute_url方法的具体用法?Python Post.get_absolute_url怎么用?Python Post.get_absolute_url使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forums.models.Post
的用法示例。
在下文中一共展示了Post.get_absolute_url方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post_new
# 需要导入模块: from forums.models import Post [as 别名]
# 或者: from forums.models.Post import get_absolute_url [as 别名]
def post_new(request, topic_id, quoted_post_id=None):
topic = get_object_or_404(Topic.objects.select_related(), pk=topic_id)
if topic.is_closed:
if not request.user.is_staff:
messages.error(request, "You are not allowed to post in closed topics.")
return redirect(topic.get_absolute_url())
else:
messages.info(request, "Note: This topic is closed.")
if not can_post_reply(request.user, topic.forum):
messages.error(request, "You are not allowed to reply on this forum.")
return redirect(topic.get_absolute_url())
if request.method == 'POST':
form = PostForm(request.POST)
if form.is_valid():
content = form.cleaned_data['content']
post = Post(topic=topic, author=request.user,
author_ip=request.META['REMOTE_ADDR'], content=content)
post.save()
messages.success(request, "Your reply has been saved.")
return redirect(post.get_absolute_url())
else:
form = PostForm()
if quoted_post_id:
try:
quoted_post = Post.objects.get(pk=quoted_post_id, topic=topic)
form.initial = {'content': "[quote=%s]%s[/quote]" %
(quoted_post.author, quoted_post.content)}
except Post.DoesNotExist:
messages.warning(request, "You tried to quote a post which "
"doesn't exist or it doesn't belong to topic you are "
"replying to. Nice try, Kevin.")
return {'topic': topic, 'form': form}