feat: added forms.py to model the forum's post form

parent fffc9323
from django.forms import ModelForm
from homepage.models import WidgetUser
from .models import Post
class PostForm(ModelForm):
class Meta:
model = Post
fields = ["post_title", "post_body", "author"]
\ No newline at end of file
from django.shortcuts import render from django.shortcuts import render, redirect
from django.http import HttpResponse, Http404 from django.http import HttpResponse, Http404
from django.template import loader from django.template import loader
from .models import Post, Reply from .models import Post, Reply
...@@ -11,10 +11,6 @@ def index(request): ...@@ -11,10 +11,6 @@ def index(request):
"posts_list": posts_list, "posts_list": posts_list,
} }
return HttpResponse(template.render(context, request)) return HttpResponse(template.render(context, request))
# output = "<br>".join([p.post_title for p in posts_list])
# view = "Welcome to Widget's Forum! <br>"
# return HttpResponse(view)
# return HttpResponse("Welcome to Widget's forum!")
def detail(request, post_id): def detail(request, post_id):
try: try:
...@@ -23,94 +19,6 @@ def detail(request, post_id): ...@@ -23,94 +19,6 @@ def detail(request, post_id):
except Post.DoesNotExist: except Post.DoesNotExist:
raise Http404("Post does not exist!") raise Http404("Post does not exist!")
return render(request, "forum/detail.html", {"post": post, "reply": reply}) return render(request, "forum/detail.html", {"post": post, "reply": reply})
# return HttpResponse("These are the details for post # %s" % author_id)
# def welcome(request): def add(request):
# forum_view = "FORUM POSTS: " return render(request, "forum/add.html", {"post_form": post_form})
# # posts = Post.objects.all() \ No newline at end of file
# # replies = Reply.objects.all()
# forum_view = forum_view + "<br> {} by {} {} dated {}: <br> {}".\
# format(
# Post.objects.get(author_id=1),
# Post.objects.get(author_id=1).author.first_name,
# Post.objects.get(author_id=1).author.last_name,
# Post.objects.get(author_id=1).pub_date,
# Post.objects.get(author_id=1).post_body
# )
# replies_to_first = Reply.objects.filter(associated_post_id=2)
# for reply_to_first in replies_to_first:
# forum_view = forum_view + '<br> Reply by {} {} dated {}: <br> {}'.\
# format(
# reply_to_first.author.first_name,
# reply_to_first.author.last_name,
# reply_to_first.pub_date,
# reply_to_first.reply_body
# )
# forum_view = forum_view + "<br>"
# forum_view = forum_view + "<br> {} by {} {} dated {}: <br> {}".\
# format(
# Post.objects.get(author_id=2),
# Post.objects.get(author_id=2).author.first_name,
# Post.objects.get(author_id=2).author.last_name,
# Post.objects.get(author_id=2).pub_date,
# Post.objects.get(author_id=2).post_body
# )
# replies_to_second = Reply.objects.filter(associated_post_id=3)
# for reply_to_second in replies_to_second:
# forum_view = forum_view + '<br> Reply by {} {} dated {}: <br> {}'.\
# format(
# reply_to_second.author.first_name,
# reply_to_second.author.last_name,
# reply_to_second.pub_date,
# reply_to_second.reply_body
# )
# forum_view = forum_view + "<br>"
# forum_view = forum_view + "<br> {} by {} {} dated {}: <br> {}".\
# format(
# Post.objects.get(id=4),
# Post.objects.get(id=4).author.first_name,
# Post.objects.get(id=4).author.last_name,
# Post.objects.get(id=4).pub_date,
# Post.objects.get(id=4).post_body
# )
# replies_to_third = Reply.objects.filter(associated_post_id=4)
# for reply_to_third in replies_to_third:
# forum_view = forum_view + '<br> Reply by {} {} dated {}: <br> {}'.\
# format(
# reply_to_third.author.first_name,
# reply_to_third.author.last_name,
# reply_to_third.pub_date,
# reply_to_third.reply_body
# )
# for post in posts:
# forum_view += "<br> {} by {} {} dated {}: <br> {}".\
# format(
# post.post_title,
# post.author.first_name,
# post.author.last_name,
# post.pub_date,
# post.post_body
# )
# for reply in replies:
# forum_view += '<br> Reply by {} {} dated {}: <br> {}'.\
# format(
# reply.author.first_name,
# reply.author.last_name,
# reply.pub_date,
# reply.reply_body
# )
return HttpResponse(forum_view)
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