Commit 54deb519 authored by Christian Sarabia's avatar Christian Sarabia

Merge branch 'sarabia/forum' into 'master'

Create Reply model, associations, and Forum page view

See merge request !1
parents 5f5ec24c 538be088
......@@ -5,10 +5,10 @@ def index(request):
return HttpResponse(display_announcementboard(Announcement.objects.all()))
def display_announcementboard(announcement_data):
display_output = "ANNOUNCEMENTS: <br>"
display_output = "<u><b>ANNOUNCEMENTS</u></b>: <br>"
for object in announcement_data:
display_output += '''
{title} by {first_name} {last_name} dated {date}:<br>
<b>{title} by {first_name} {last_name}</b> dated {date}:<br>
{body}<br>
Like: {like_tally}<br>
Love: {love_tally}<br>
......
......@@ -7,11 +7,11 @@ def index(request):
return HttpResponse(display_assignments(Assignment.objects.all()))
def display_assignments(data_set_assignment):
display_output = "ASSIGNMENTS: <br>"
display_output = "<u><b>ASSIGNMENTS</u></b>: <br>"
for object in data_set_assignment:
display_output += '''
Assignment Name: {name}<br>
Assignment Name: <b>{name}</b><br>
Description: {description}<br>
Perfect Score: {max_points}<br>
Passing Score: {passing_score}<br>
......
from django.contrib import admin
# Register your models here.
from .models import Post
from .models import Post, Reply
admin.site.register(Post)
\ No newline at end of file
class PostAdmin(admin.ModelAdmin):
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 homepage.models import WidgetUser
# Create your models here.
class Post(models.Model):
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")
def __str__(self):
return self.post_title
\ No newline at end of file
return "Reply from " + self.author.first_name + " " + self.author.last_name
class Meta:
verbose_name_plural = "Replies"
\ No newline at end of file
from django.http import HttpResponse
from .models import Post, Reply
# Create your views here.
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):
return HttpResponse(display_users(WidgetUser.objects.all()))
def display_users(data_list):
display_output = "WIDGET USERS: <br>"
display_output = "<u><b>WIDGET USERS</u></b>: <br>"
for objects in data_list:
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,
first_name = objects.first_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