Exemplo n.º 1
0
def post(request, post_id):
    my_post = cache.get('post/%s/' % post_id)
    if my_post is None:
        my_post = get_object_or_404(
            Post.objects.select_related(),
            pk=post_id,
            is_published=True
        )
        cache.set('post/%s/' % post_id, my_post)

    ctype = ContentType.objects.get_for_model(Post)

    comments = Comment.get_all_comments(ctype, post_id)

    if request.user.is_authenticated():
        form = CommentForm(prefix='comment')
    else:
        form = CommentFormAnon(prefix='comment')

    return render(
        request,
        'blog/post.html',
        {'post': my_post, 'comments': comments, 'form': form, 'belong_content_type_id': ContentType.objects.get_for_model(Post).id, 'belong_object_id': my_post.id})