def post_new(request): if request.method == "POST": form = PostForm(request.POST) if form.is_valid(): post = form.save(commit=False) post.Autor = request.user post.save() return render(request, 'base/news_edit.html', {'form': form}) else: form = PostForm() return render_to_response('base/news_edit.html', {'form': form})
def post_edit(request, pk): post = get_object_or_404(Post, pk=pk) if request.method == "POST": form = PostForm(request.POST, instance=post) if form.is_valid(): post = form.save(commit=False) post.autor = request.user post.save() return redirect('post_edit', pk=post.pk) else: form = PostForm(instance=post) return render(request, 'base/news_edit.html', {'form': form})
def reply_topic(request, pk, topic_pk): topic = get_object_or_404(Topic, board__pk=pk, pk=topic_pk) if request.method == 'POST': form = PostForm(request.POST) if form.is_valid(): post = form.save(commit=False) post.topic = topic post.created_by = request.user post.save() topic.last_updated = timezone.now() topic.save() topic_url = reverse('topic_posts', kwargs={'pk': pk, 'topic_pk': topic_pk}) topic_post_url = '{url}?page={page}#{id}'.format( url=topic_url, id=post.pk, page=topic.get_page_count() ) return redirect(topic_post_url) else: form = PostForm() return render(request, 'reply_topic.html', {'topic': topic, 'form': form})