Commit a14fc9da authored by justin's avatar justin

Merge remote-tracking branch 'origin/forum_wip'

parents a05b4c1e 86c86d3b
from django.contrib import admin from django.contrib import admin
from .models import ForumPost, Reply
# Register your models here.
class ForumPostAdmin(admin.ModelAdmin):
model = ForumPost
list_display = ("title", "author", "body", "pub_datetime")
class ReplyAdmin(admin.ModelAdmin):
model = Reply
list_display = ("forum", "author", "body", "pub_datetime")
admin.site.register(ForumPost, ForumPostAdmin)
admin.site.register(Reply, ReplyAdmin)
from django.db import models from django.db import models
from dashboard.models import WidgetUser
# Create your models here.
class ForumPost(models.Model):
title = models.CharField(max_length=50)
body = models.CharField(max_length=1000)
author = models.ForeignKey(WidgetUser, on_delete=models.CASCADE)
pub_datetime = models.DateTimeField("Published Date and Time", auto_now_add=True)
def __str__(self):
return self.title
class Reply(models.Model):
forum = models.ForeignKey(ForumPost, on_delete=models.CASCADE)
body = models.CharField(max_length=1000)
author = models.ForeignKey(WidgetUser, on_delete=models.CASCADE)
pub_datetime = models.DateTimeField("Published Date and Time", auto_now_add=True)
def __str__(self):
return self.body
from django.urls import path
from . import views
urlpatterns = [
path("", views.forum, name="index"),
]
from django.shortcuts import render from django.http import HttpResponse
from .models import ForumPost
# Create your views here.
def forum(request):
# fetch forum posts and replies
forum = ForumPost.objects.all()
forum_view = "Widget's Forum <br> <br> Forum Posts:<br>"
for post in forum:
post_replies = post.reply_set.all()
forum_view += """
{} by {} posted {}: <br>
{} <br>
""".format(
post.title,
post.author,
post.pub_datetime.strftime("%m/%d/%Y, %I:%M %p"),
post.body,
)
for reply in post_replies:
if reply.forum == post:
forum_view += """
Reply by {} posted {}: <br>
{} <br>
""".format(
reply.author,
reply.pub_datetime.strftime("%m/%d/%Y, %I:%M %p"),
reply.body,
)
forum_view += "<br>"
return HttpResponse(forum_view)
...@@ -20,4 +20,5 @@ urlpatterns = [ ...@@ -20,4 +20,5 @@ urlpatterns = [
path("admin/", admin.site.urls), path("admin/", admin.site.urls),
path("dashboard/", include("dashboard.urls")), path("dashboard/", include("dashboard.urls")),
path("calendar/", include("calendar_app.urls", namespace="calendar_app")), path("calendar/", include("calendar_app.urls", namespace="calendar_app")),
path("forum/", include("forum.urls")),
] ]
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