Commit 03d1052b authored by Ysabella Panghulan's avatar Ysabella Panghulan

fixed views format and typo in models and admin, changed post to forum_post

parent e2b352df
......@@ -3,7 +3,7 @@ from .models import ForumPost, Reply
# Register your models here.
class ReplyInLine(admin.TabularInLine):
class ReplyInLine(admin.TabularInline):
model = Reply
class ForumPostAdmin(admin.ModelAdmin):
......
......@@ -9,14 +9,14 @@ class ForumPost(models.Model):
author = models.ForeignKey(WidgetUser, on_delete = models.CASCADE)
pub_datetime = models.DateTimeField()
def _str_(self):
def __str__(self):
return self.title
class Reply(models.Model):
body = models.CharField(max_length = 300)
author = models.ForeignKey(WidgetUser, on_delete = models.CASCADE)
pub_datetime = models.DateTimeField()
post = models.ForeignKey(ForumPost, on_delete = models.CASCADE)
forum_post = models.ForeignKey(ForumPost, on_delete = models.CASCADE)
def _str_(self):
def __str__(self):
return self.author
......@@ -2,16 +2,17 @@ from django.shortcuts import render
from django.http import HttpResponse
from .models import ForumPost, Reply
# Create your views here.
def index(request):
posts = ForumPost.objects.all()
replies = Reply.objects.all()
welcomeMessage = "Widget's Forum<br><br>Forum Posts:<br>"
welcomeMessage = 'Widget\'s Forum<br><br>Forum Posts:<br>'
for post in posts:
for reply in replies:
if reply.post.title == post.title:
welcomeMessage = welcomeMessage + post.title + " by " + post.author.first_name + " " + post.author.last_name + " posted " + post.pub_datetime.strftime('%I:%M %p') + ":<br>" + post.body + "<br>" + "Reply by " + reply.author.first_name + " " + reply.author.last_name + " posted " + reply.pub_datetime.strftime('%I:%M %p') + ":<br>" + reply.body + "<br><br>"
if reply.forum_post.title == post.title:
welcomeMessage += post.title + ' by ' + post.author.first_name + ' ' + post.author.last_name
welcomeMessage += ' posted ' + post.pub_datetime.strftime('%m/%d/%Y, %I:%M %p') + ':<br>' + post.body + '<br>'
welcomeMessage += 'Reply by ' + reply.author.first_name + ' ' + reply.author.last_name + ' posted '
welcomeMessage += reply.pub_datetime.strftime('%m/%d/%Y, %I:%M %p') + ':<br>' + reply.body + '<br><br>'
return HttpResponse(welcomeMessage)
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