示例#1
0
def post_details(request, pk):
    post = UserPost.objects.get(pk=pk)
    title = post.text[:15] + "[...]"
    comments = UserPostComment.objects. \
            filter(post=post).order_by('-date_added')
    context = {
        'post': post, 
        'title': title,
        'comments': comments,
    }
    if request.method == 'GET':
        form = UserPostCommentForm()
        context['form'] = form
        return render(request, 'post_details.html', context)
    elif request.method == 'POST':
        form = UserPostCommentForm(request.POST)
        if form.is_valid():
            text = form.cleaned_data['text']
            author = form.cleaned_data['author']
            user_comment = UserPostComment(text=text, author=author, post=post)
            user_comment.save()
            return redirect('post_details', pk=pk)
        else:
            context['form'] = form
            return render(request, 'post_details.html', context)
示例#2
0
def post_details(request, pk):
    if (request.method == 'GET'):
        form = UserPostCommentForm()
        post = UserPost.objects.get(pk=pk)
        comments = UserPostComment.objects.filter(post=post) \
            .order_by('-date_added')
        context = {'post': post, 'comments': comments, 'form': form}
        return render(request, 'post_details.html', context)
    elif request.method == 'POST':
        form = UserPostCommentForm(request.POST)
        if form.is_valid():
            text = form.cleaned_data['text']
            comment = UserPostComment(text=text)
            comment.post_id = pk
            comment.save()
        return redirect('/post/{}/'.format(pk))
示例#3
0
def post_details(request, pk):
    if request.method == 'POST':
        form = UserPostCommentForm(request.POST)
        if form.is_valid():
            text = form.cleaned_data['text']
            comment = UserPostComment(text=text)
            comment.post_id = pk
            comment.save()

    post = UserPost.objects.get(pk=pk)
    comments = post.userpostcomment_set.all().order_by('-date_added')
    form = UserPostCommentForm()

    context = {'post': post, 'comments': comments, 'form': form}

    return render(request, 'post_details.html', context)
示例#4
0
def post_details(request, pk):
    post = UserPost.objects.get(pk=pk)
    if request.method == 'GET':
        form = UserPostCommentForm()
        context = {
            'post': post,
            'form': form,
        }
        return render(request, 'post_details.html', context)
    elif request.method == 'POST':
        form = UserPostCommentForm(request.POST)
        if form.is_valid():
            text = form.cleaned_data['text']
            comment = UserPostComment(text=text,
                                      post=post,
                                      author=request.user)
            comment.save()
        return redirect('post_details', pk=pk)
示例#5
0
def post_details(request, pk):
    post = UserPost.objects.get(pk=pk)
    if request.method == 'GET':
        comments = UserPostComment.objects.filter(
            post_id=post).order_by('-date_added')
        form = UserPostCommentForm()
        context = {
            'post': post,
            'form': form,
            'comments': comments,
        }
        return render(request, 'post_details.html', context)
    elif request.method == 'POST':
        form = UserPostCommentForm(request.POST)
        if form.is_valid():
            text = form.cleaned_data['text']
            user_post_comment = UserPostComment(text=text, post=post)
            user_post_comment.save()
        return redirect('post_details', pk=pk)