Commit eecd1b6e authored by Rurik Serzo's avatar Rurik Serzo

Created the formatting for forum view

parent eec7efe8
...@@ -8,8 +8,28 @@ class Post(models.Model): ...@@ -8,8 +8,28 @@ class Post(models.Model):
pub_date = models.DateField(auto_now_add=True) pub_date = models.DateField(auto_now_add=True)
author = models.ForeignKey(WidgetUser,on_delete=models.CASCADE,null=True) author = models.ForeignKey(WidgetUser,on_delete=models.CASCADE,null=True)
def __str__(self):
return self.post_title
def getPost(self):
return "{} by {} {} dated {}:<br>{}<br>".format(
self.post_title,
self.author.first_name,
self.author.last_name,
self.pub_date,
self.post_body
)
class Reply(models.Model): class Reply(models.Model):
reply_body = models.TextField() reply_body = models.TextField()
pub_date = models.DateField(auto_now_add=True) pub_date = models.DateField(auto_now_add=True)
author = models.ForeignKey(WidgetUser,on_delete=models.CASCADE,null=True) author = models.ForeignKey(WidgetUser,on_delete=models.CASCADE,null=True)
post = models.ForeignKey(Post,on_delete=models.CASCADE,null=True,related_name="posts") post = models.ForeignKey(Post,on_delete=models.CASCADE,null=True,related_name="posts")
\ No newline at end of file
def getReply(self):
return "Reply by {} {} {}:<br>{}<br>".format(
self.author.first_name,
self.author.last_name,
self.pub_date,
self.reply_body
)
\ No newline at end of file
from django.shortcuts import render from django.shortcuts import render
from django.http import HttpResponse from django.http import HttpResponse
from .models import Post, Reply
def index(request): def index(request):
return HttpResponse("Welcome to Widget's Forum!") posts = Post.objects.all()
formatted_posts = "FORUM POSTS:<br>"
for post in posts:
formatted_posts += post.getPost()
replies = Reply.objects.all().filter(post__post_title=post)
for reply in replies:
formatted_posts += reply.getReply()
formatted_posts += "<br>"
return HttpResponse(formatted_posts)
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