Commit 9e9c3b8f authored by Migs Atienza's avatar Migs Atienza

Finished Views + Updated Models' __str__

parent eb27b0c9
No preview for this file type
...@@ -7,10 +7,16 @@ class ForumPost(models.Model): ...@@ -7,10 +7,16 @@ class ForumPost(models.Model):
author = models.CharField(max_length=100) author = models.CharField(max_length=100)
pub_datetime = models.DateTimeField() pub_datetime = models.DateTimeField()
def __str__(self):
return '{} by {}'.format(self.title, self.author)
class Reply(models.Model): class Reply(models.Model):
body = models.TextField(max_length=1000) body = models.TextField(max_length=1000)
author = models.CharField(max_length=100) author = models.CharField(max_length=100)
pub_datetime = models.DateTimeField() pub_datetime = models.DateTimeField()
forum_post = models.ForeignKey(ForumPost, on_delete=models.CASCADE) forum_post = models.ForeignKey(ForumPost, on_delete=models.CASCADE)
def __str__(self):
return '{}\'s reply to {}'.format(self.author, self.forum_post)
# Create your models here. # Create your models here.
...@@ -7,15 +7,17 @@ from .models import ForumPost, Reply ...@@ -7,15 +7,17 @@ from .models import ForumPost, Reply
def index(request): def index(request):
page_content = """<H1>Widget’s Forum</H1>""" page_content = """<H1>Widget’s Forum</H1>"""
for forum in ForumPost.objects.all(): for forum in ForumPost.objects.all():
newForumDateTime = forum.pub_datetime.strftime("%m-%d-%Y %I:%M %p")
page_content += """<br> page_content += """<br>
{} by {} posted {}:<br> {} by {} posted {}:<br>
{}<br> {}<br>
""".format(forum.title, forum.author, forum.pub_datetime, forum.body) """.format(forum.title, forum.author, newForumDateTime, forum.body)
for reply in Reply.objects.all(): for reply in Reply.objects.all():
if reply.forum_post == forum: if reply.forum_post == forum:
page_content += """Reply by {} posted {}: newReplyDateTime = reply.pub_datetime.strftime("%m-%d-%Y %I:%M %p")
{} page_content += """Reply by {} posted {}:<br>
""".format(reply.author, reply.pub_datetime, reply.body) {}<br>
""".format(reply.author, newReplyDateTime, reply.body)
return HttpResponse(page_content) return HttpResponse(page_content)
# Create your views here. # Create your views here.
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