Commit 36d2898e authored by Deokhyun Lee's avatar Deokhyun Lee

Merge branch 'forum_wip' into 'master'

Request for forum_to master

See merge request !10
parents dc43d21b 6d286e50
from django.contrib import admin
from .models import ForumPost, Reply
# Register your models here.
class ReplyInLine(admin.TabularInline):
model = Reply
class ForumPostAdmin(admin.ModelAdmin):
model = ForumPost
list_display = ("title", "author", "body", "pub_datetime")
inlines = [ReplyInLine]
class ReplyAdmin(admin.ModelAdmin):
list_display = ("forum_post", "author", "body", "pub_datetime")
admin.site.register(ForumPost, ForumPostAdmin)
admin.site.register(Reply, ReplyAdmin)
# Generated by Django 4.1.7 on 2023-03-06 11:20
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
('dashboard', '0002_alter_widgetuser_department'),
]
operations = [
migrations.CreateModel(
name='ForumPost',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('title', models.CharField(max_length=50)),
('body', models.TextField(max_length=1000)),
('pub_datetime', models.DateTimeField(auto_now_add=True, verbose_name='Published Date and Time')),
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='dashboard.widgetuser')),
],
),
migrations.CreateModel(
name='Reply',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('body', models.CharField(max_length=1000)),
('pub_datetime', models.DateTimeField(auto_now_add=True, verbose_name='Published Date and Time')),
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='dashboard.widgetuser')),
('forum_post', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='forum.forumpost')),
],
),
]
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.TextField(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):
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)
forum_post = models.ForeignKey(ForumPost, on_delete=models.CASCADE)
def __str__(self):
return self.body
from django.urls import path
from . import views
urlpatterns = [
path("", views.forumIndex, name="forumIndex"),
]
\ No newline at end of file
from django.shortcuts import render
from django.http import HttpResponse
from .models import ForumPost, Reply
# Create your views here.
def forumIndex(request):
# fetch forum posts and replies
forum = ForumPost.objects.all()
replies = Reply.objects.all()
forum_output = "Widget's Forum <br><br> Forum Posts:<br>"
for post in forum:
forum_output = (forum_output + post.title + " by " + post.author.first_name + " " + post.author.last_name +
" posted " + post.pub_datetime.strftime('%m/%d/%Y, %I:%M %p') + ":<br>" +
post.body + "<br>"
)
for reply in replies:
if reply.forum_post.title == post.title:
forum_output = (forum_output + "Reply by " + reply.author.first_name + " " + reply.author.last_name
+ " posted " + reply.pub_datetime.strftime('%m/%d/%Y, %I:%M %p') + ":<br>" +
reply.body + "<br>"
)
forum_output = forum_output + "<br>"
return HttpResponse(forum_output)
......@@ -20,5 +20,6 @@ urlpatterns = [
path("admin/", admin.site.urls),
path("dashboard/", include("dashboard.urls", namespace="dashboard")),
path("assignments/", include("assignments.urls")),
path("forum/", include("forum.urls")),
path("calendar/", include("calendar_app.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