Commit 23016a61 authored by Migs Atienza's avatar Migs Atienza

Merge branch 'forum' into 'master'

Forum

See merge request !3
parents d37c11d2 9e9c3b8f
CSCI 40-F
Atienza, Miguel Luis Antionio, (M.I), (ID#); Benito, Matthew Josh, (M.I), (ID#); Garsin, Mariam Yasmin, B, 206034; Gomez, Enrnique Jose Stefan, P, 212804; Que, Nate Brevin, A, 214754;
Atienza, Miguel Luis Antionio, A, 210523; Benito, Matthew Josh, (M.I), (ID#); Garsin, Mariam Yasmin, B, 206034; Gomez, Enrnique Jose Stefan, P, 212804; Que, Nate Brevin, A, 214754;
Midterm Project: Widget v1
App Assignments:
Dashboard - Stefan
......
No preview for this file type
# Default ignored files
/shelf/
/workspace.xml
<?xml version="1.0" encoding="UTF-8"?>
<module type="PYTHON_MODULE" version="4">
<component name="NewModuleRootManager">
<content url="file://$MODULE_DIR$" />
<orderEntry type="jdk" jdkName="Python 3.9 (myenv)" jdkType="Python SDK" />
<orderEntry type="sourceFolder" forTests="false" />
</component>
</module>
\ No newline at end of file
<component name="InspectionProjectProfileManager">
<settings>
<option name="USE_PROJECT_PROFILE" value="false" />
<version value="1.0" />
</settings>
</component>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectRootManager" version="2" project-jdk-name="Python 3.9 (myenv)" project-jdk-type="Python SDK" />
<component name="PyCharmProfessionalAdvertiser">
<option name="shown" value="true" />
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="ProjectModuleManager">
<modules>
<module fileurl="file://$PROJECT_DIR$/.idea/forum.iml" filepath="$PROJECT_DIR$/.idea/forum.iml" />
</modules>
</component>
</project>
\ No newline at end of file
<?xml version="1.0" encoding="UTF-8"?>
<project version="4">
<component name="VcsDirectoryMappings">
<mapping directory="$PROJECT_DIR$/../.." vcs="Git" />
</component>
</project>
\ No newline at end of file
from django.contrib import admin
from .models import ForumPost, Reply
class ForumPostAdmin(admin.ModelAdmin):
model = ForumPost
class ReplyAdmin(admin.ModelAdmin):
model = Reply
# Register your models here.
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 4.1.6 on 2023-03-05 08:05
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
]
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=100)),
('body', models.TextField(max_length=1000)),
('author', models.CharField(max_length=100)),
('pub_datetime', models.DateTimeField()),
],
),
migrations.CreateModel(
name='Reply',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('body', models.TextField(max_length=1000)),
('author', models.CharField(max_length=100)),
('pub_datetime', models.DateTimeField()),
('forum_post', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='forum.forumpost')),
],
),
]
from django.db import models
class ForumPost(models.Model):
title = models.CharField(max_length=100)
body = models.TextField(max_length=1000)
author = models.CharField(max_length=100)
pub_datetime = models.DateTimeField()
def __str__(self):
return '{} by {}'.format(self.title, self.author)
class Reply(models.Model):
body = models.TextField(max_length=1000)
author = models.CharField(max_length=100)
pub_datetime = models.DateTimeField()
forum_post = models.ForeignKey(ForumPost, on_delete=models.CASCADE)
def __str__(self):
return '{}\'s reply to {}'.format(self.author, self.forum_post)
# Create your models here.
from django.test import TestCase
# Create your tests here.
from django.contrib import admin
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):
page_content = """<H1>Widget’s Forum</H1>"""
for forum in ForumPost.objects.all():
newForumDateTime = forum.pub_datetime.strftime("%m-%d-%Y %I:%M %p")
page_content += """<br>
{} by {} posted {}:<br>
{}<br>
""".format(forum.title, forum.author, newForumDateTime, forum.body)
for reply in Reply.objects.all():
if reply.forum_post == forum:
newReplyDateTime = reply.pub_datetime.strftime("%m-%d-%Y %I:%M %p")
page_content += """Reply by {} posted {}:<br>
{}<br>
""".format(reply.author, newReplyDateTime, reply.body)
return HttpResponse(page_content)
# Create your views here.
......@@ -44,6 +44,7 @@ INSTALLED_APPS = [
'django.contrib.staticfiles',
'assignments',
'dashboard',
'forum',
]
MIDDLEWARE = [
......
......@@ -4,5 +4,6 @@ from django.urls import include, path
urlpatterns = [
path('assignments/', include('assignments.urls', namespace="assignments")),
path('dashboard/', include('dashboard.urls', namespace="dashboard")),
path('forum/', include('forum.urls', namespace="forum")),
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