Commit 538be088 authored by Christian Sarabia's avatar Christian Sarabia

Create Reply model, associations, and Forum page view

parent 5f5ec24c
...@@ -5,10 +5,10 @@ def index(request): ...@@ -5,10 +5,10 @@ def index(request):
return HttpResponse(display_announcementboard(Announcement.objects.all())) return HttpResponse(display_announcementboard(Announcement.objects.all()))
def display_announcementboard(announcement_data): def display_announcementboard(announcement_data):
display_output = "ANNOUNCEMENTS: <br>" display_output = "<u><b>ANNOUNCEMENTS</u></b>: <br>"
for object in announcement_data: for object in announcement_data:
display_output += ''' display_output += '''
{title} by {first_name} {last_name} dated {date}:<br> <b>{title} by {first_name} {last_name}</b> dated {date}:<br>
{body}<br> {body}<br>
Like: {like_tally}<br> Like: {like_tally}<br>
Love: {love_tally}<br> Love: {love_tally}<br>
......
...@@ -7,11 +7,11 @@ def index(request): ...@@ -7,11 +7,11 @@ def index(request):
return HttpResponse(display_assignments(Assignment.objects.all())) return HttpResponse(display_assignments(Assignment.objects.all()))
def display_assignments(data_set_assignment): def display_assignments(data_set_assignment):
display_output = "ASSIGNMENTS: <br>" display_output = "<u><b>ASSIGNMENTS</u></b>: <br>"
for object in data_set_assignment: for object in data_set_assignment:
display_output += ''' display_output += '''
Assignment Name: {name}<br> Assignment Name: <b>{name}</b><br>
Description: {description}<br> Description: {description}<br>
Perfect Score: {max_points}<br> Perfect Score: {max_points}<br>
Passing Score: {passing_score}<br> Passing Score: {passing_score}<br>
......
from django.contrib import admin from django.contrib import admin
# Register your models here. # Register your models here.
from .models import Post from .models import Post, Reply
admin.site.register(Post) class PostAdmin(admin.ModelAdmin):
\ No newline at end of file model = Post
search_fields = ['post_title', 'post_body','author']
list_display = ('post_title', 'post_body', 'pub_date', 'author')
class ReplyAdmin(admin.ModelAdmin):
model = Reply
search_fields = ['post','reply_body','author']
list_display = ('post','reply_body', 'pub_date', 'author')
admin.site.register(Post, PostAdmin)
admin.site.register(Reply, ReplyAdmin)
\ No newline at end of file
from calendar import c
from django.db import models from django.db import models
from homepage.models import WidgetUser
# Create your models here. # Create your models here.
class Post(models.Model): class Post(models.Model):
post_title = models.CharField(max_length=50) post_title = models.CharField(max_length=50)
post_body = models.CharField(max_length=500) post_body = models.TextField(max_length=1500)
pub_date = models.DateTimeField("date published")
author = models.ForeignKey(WidgetUser, on_delete=models.CASCADE)
def __str__(self):
return self.post_title
class Reply(models.Model):
post = models.ForeignKey(Post, on_delete=models.CASCADE)
reply_body = models.TextField(max_length=1500)
author = models.ForeignKey(WidgetUser, on_delete=models.CASCADE, default=1)
pub_date = models.DateTimeField("date published") pub_date = models.DateTimeField("date published")
def __str__(self): def __str__(self):
return self.post_title return "Reply from " + self.author.first_name + " " + self.author.last_name
\ No newline at end of file
class Meta:
verbose_name_plural = "Replies"
\ No newline at end of file
from django.http import HttpResponse from django.http import HttpResponse
from .models import Post, Reply
# Create your views here. # Create your views here.
def index(request): def index(request):
return HttpResponse("Welcome to Widget’s Forum!") return HttpResponse(display_forum(Post.objects.all()))
def display_forum(post_data):
display_output = "<u><b>FORUM POSTS</u></b>:<br>"
for post in post_data:
display_output += f"<b>{post.post_title} by {post.author.first_name} {post.author.last_name}</b> dated {str(post.pub_date)}:\
<br>{post.post_body}"
replies = Reply.objects.filter(post=post)
for reply in replies:
display_output += f"<br><b>Reply by {reply.author.first_name} {reply.author.last_name}</b> dated {reply.pub_date}:\
<br>{reply.reply_body}"
display_output += "<br><br>"
return display_output
\ No newline at end of file
...@@ -6,11 +6,11 @@ def index(request): ...@@ -6,11 +6,11 @@ def index(request):
return HttpResponse(display_users(WidgetUser.objects.all())) return HttpResponse(display_users(WidgetUser.objects.all()))
def display_users(data_list): def display_users(data_list):
display_output = "WIDGET USERS: <br>" display_output = "<u><b>WIDGET USERS</u></b>: <br>"
for objects in data_list: for objects in data_list:
display_output += ''' display_output += '''
{last_name}, {first_name} {middle_name}: {id}, {email}, {dept}, {home}<br> <b>{last_name}, {first_name} {middle_name}</b>: {id}, {email}, {dept}, {home}<br>
'''.format(last_name = objects.last_name, '''.format(last_name = objects.last_name,
first_name = objects.first_name, first_name = objects.first_name,
middle_name = objects.middle_name, middle_name = objects.middle_name,
......
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