Beispiel #1
0
def post_new(request):
    if request.method == "POST":
        form = PostForm(request.POST)
        if form.is_valid():
            post = form.save(commit=False)
            post.author = request.user
            post.save()
            return redirect('Wiadomosci.views.post_detail', pk=post.pk)
    else:
        form = PostForm()
    return render(request, 'blog/edit_news.html', {'form': form})
Beispiel #2
0
def post_edit(request, pk):
    post = get_object_or_404(News, pk=pk)
    if post.author.id == request.user.id:
        if request.method == "POST":
            form = PostForm(request.POST, instance=post)
            if form.is_valid():
                post = form.save(commit=False)
                post.author = request.user
                post.save()
                return redirect('Wiadomosci.views.post_detail', pk=post.pk)
        else:
            form = PostForm(instance=post)
        return render(request, 'blog/edit_news.html', {'form': form})
    return redirect('Wiadomosci.views.post_list')