Commit 80abf5e8 authored by Ysabella Panghulan's avatar Ysabella Panghulan

Merge widget_forum branch to main

parents 859a772a fc0e6ade
...@@ -31,4 +31,5 @@ Signatures: ...@@ -31,4 +31,5 @@ Signatures:
(sgd) Ysabella B. Panghulan, March 2, 2023 (sgd) Ysabella B. Panghulan, March 2, 2023
(sgd) Julia Anishka M. Espera, March 3, 2023 (sgd) Julia Anishka M. Espera, March 3, 2023
(sgd) Gabriel G. Garrero, March 3, 2023 (sgd) Gabriel G. Garrero, March 3, 2023
(sgd) Trisha Angel P. Millena, March 3, 2023 (sgd) Trisha Angel P. Millena, March 3, 2023
\ No newline at end of file (sgd) Caryn Bryne C. Lopez-Go, March 4, 2023
\ No newline at end of file
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', 'body', 'pub_datetime')
inlines = [ReplyInLine]
class ReplyAdmin(admin.ModelAdmin):
model = Reply
list_display = ('body', 'pub_datetime')
admin.site.register(ForumPost, ForumPostAdmin)
admin.site.register(Reply, ReplyAdmin)
\ No newline at end of file
from django.apps import AppConfig
class ForumConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField'
name = 'forum'
# Generated by Django 3.2 on 2023-03-04 15:37
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
('dashboard', '0001_initial'),
]
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=300)),
('body', models.TextField(max_length=500)),
('pub_datetime', models.DateTimeField()),
('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=300)),
('pub_datetime', models.DateTimeField()),
('author', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='dashboard.widgetuser')),
('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 = 300)
body = models.TextField(max_length = 500)
author = models.ForeignKey(WidgetUser, on_delete = models.CASCADE)
pub_datetime = models.DateTimeField()
def __str__(self):
return self.title
class Reply(models.Model):
body = models.CharField(max_length = 300)
author = models.ForeignKey(WidgetUser, on_delete = models.CASCADE)
pub_datetime = models.DateTimeField()
forum_post = models.ForeignKey(ForumPost, on_delete = models.CASCADE)
def __str__(self):
return self.body
from django.test import TestCase
# Create your tests here.
from django.urls import path
from .views import index
urlpatterns = [
path('', index, name = "index")
]
app_name = "forum"
\ No newline at end of file
from django.shortcuts import render
from django.http import HttpResponse
from .models import ForumPost, Reply
def index(request):
posts = ForumPost.objects.all()
replies = Reply.objects.all()
welcomeMessage = 'Widget\'s Forum<br><br>Forum Posts:<br>'
for post in posts:
for reply in replies:
if reply.forum_post.title == post.title:
welcomeMessage += post.title + ' by ' + post.author.first_name + ' ' + post.author.last_name
welcomeMessage += ' posted ' + post.pub_datetime.strftime('%m/%d/%Y, %I:%M %p') + ':<br>' + post.body + '<br>'
welcomeMessage += 'Reply by ' + reply.author.first_name + ' ' + reply.author.last_name + ' posted '
welcomeMessage += reply.pub_datetime.strftime('%m/%d/%Y, %I:%M %p') + ':<br>' + reply.body + '<br><br>'
return HttpResponse(welcomeMessage)
...@@ -35,6 +35,7 @@ ALLOWED_HOSTS = [] ...@@ -35,6 +35,7 @@ ALLOWED_HOSTS = []
# Application definition # Application definition
INSTALLED_APPS = [ INSTALLED_APPS = [
'forum',
'dashboard', 'dashboard',
'django.contrib.admin', 'django.contrib.admin',
'django.contrib.auth', 'django.contrib.auth',
......
...@@ -17,6 +17,7 @@ from django.contrib import admin ...@@ -17,6 +17,7 @@ from django.contrib import admin
from django.urls import include, path from django.urls import include, path
urlpatterns = [ urlpatterns = [
path('forum/', include("forum.urls", namespace = "forum")),
path('dashboard/', include('dashboard.urls', namespace = "dashboard")), path('dashboard/', include('dashboard.urls', namespace = "dashboard")),
path('admin/', admin.site.urls), path('admin/', admin.site.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