Add new announcement view and change index view to obv

parent 0a9fa98c
from urllib import response
from django.http import HttpResponse, Http404
from django.shortcuts import render
from django.shortcuts import render, redirect
from django.views import View
from forum.models import Post
from forum.models import Reply
# Create your views here.
def index(request):
from .forms import PostForm
# Create your views here.
class IndexView(View):
def get(self, request):
post_list = Post.objects.order_by("pub_date")
context = {
......@@ -27,11 +31,22 @@ def details (request, post_id):
return render(request, "forum/details.html", {"posts":posts, 'reply_list':reply_list})
"""post_objects = Post.objects.all()
reply_objects = Reply.objects.all()
response = "FORUM POSTS:"
def add(request):
for post in post_objects:
if request.method == "POST":
post_form = PostForm(request.POST, request.FILES)
if post_form.is_valid():
post_form.save()
return redirect("forum:add")
else:
post_form = PostForm()
return render(request, "forum/add.html", {"post_form": post_form})
"""post_objects = Post.objects.all()
reply_objects = Reply.objects.all()
response = "FORUM POSTS:"
for post in post_objects:
response = (response + f"<br> {post.post_title} by "
+ f"{post.author.first_name} {post.author.last_name} "
+ f"dated {post.pub_date.date()}:<br> {post.post_body} <br>")
......@@ -41,5 +56,4 @@ def details (request, post_id):
+ f"{reply.author.first_name} {reply.author.last_name} "
+ f"dated {reply.pub_date.date()}:<br> {reply.reply_body} <br>")
return HttpResponse(response)"""
\ No newline at end of file
return HttpResponse(response)"""
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment