Commit 6f2945ed authored by Ray Rafael Abenido's avatar Ray Rafael Abenido

New Feature: merged 'forum' branch with current work. All functionality added...

New Feature: merged 'forum' branch with current work. All functionality added in 'forum' is now in master branch. See forum branch for more details.
parent 48f11fda
# widget_django unchained # widget_django unchained
# AUTHORS ## AUTHORS
1. John Raymon Yu - Assignments 1. John Raymon Yu - Assignments
2. Jose Emmanuel B. Laurel - Homepage 2. Jose Emmanuel B. Laurel - Homepage
3. Joshua Graham Son - Announcements 3. Joshua Graham Son - Announcements
4. Ray Rafael Abenido - Forum 4. Ray Rafael Abenido - Forum
# LAB SUBMISSIONS ## LAB SUBMISSIONS
1. Lab 1 Video Link: https://youtu.be/QsmKkNtBzik 1. Lab 1 Video Link: https://youtu.be/QsmKkNtBzik
\ No newline at end of file
from django.contrib import admin from django.contrib import admin
# Register your models here. # Register your models here.
from .models import Post from .models import Post, Reply
admin.site.register(Post) admin.site.register(Post)
admin.site.register(Reply)
\ No newline at end of file
# Generated by Django 3.2.12 on 2022-03-31 13:08
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('forum', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='Reply',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('reply_body', models.TextField()),
('pub_date', models.DateTimeField(auto_now_add=True)),
],
),
]
# Generated by Django 3.2.12 on 2022-03-31 13:31
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('homepage', '0003_rename_id_name_widgetuser_id_num'),
('forum', '0002_reply'),
]
operations = [
migrations.AddField(
model_name='post',
name='author',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='homepage.widgetuser'),
),
migrations.AddField(
model_name='reply',
name='author',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='homepage.widgetuser'),
),
]
# Generated by Django 3.2.12 on 2022-03-31 13:49
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('homepage', '0003_rename_id_name_widgetuser_id_num'),
('forum', '0003_auto_20220331_2131'),
]
operations = [
migrations.AddField(
model_name='post',
name='reply_chain',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='forum.reply'),
),
migrations.AddField(
model_name='reply',
name='reply_chain',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, to='forum.reply'),
),
migrations.AlterField(
model_name='post',
name='author',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='homepage.widgetuser'),
),
migrations.AlterField(
model_name='reply',
name='author',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='homepage.widgetuser'),
),
]
...@@ -2,9 +2,19 @@ from django.db import models ...@@ -2,9 +2,19 @@ from django.db import models
# Create your models here. # Create your models here.
class Post(models.Model): class Post(models.Model):
author = models.ForeignKey('homepage.WidgetUser', on_delete=models.CASCADE)
post_title = models.CharField(max_length=100) post_title = models.CharField(max_length=100)
post_body = models.TextField() post_body = models.TextField()
pub_date = models.DateTimeField(auto_now_add=True) pub_date = models.DateTimeField(auto_now_add=True)
reply_chain = models.ForeignKey('Reply', on_delete=models.CASCADE,
blank=True,null= True)
def __str__(self): def __str__(self):
return self.post_title return self.post_title
class Reply(models.Model):
author = models.ForeignKey('homepage.WidgetUser', on_delete=models.CASCADE)
reply_body = models.TextField()
pub_date = models.DateTimeField(auto_now_add=True)
reply_chain = models.ForeignKey('Reply', on_delete=models.CASCADE,
blank=True,null= True)
<p>
{% for post in posts %}
<h2>FORUM POSTS:</h2>
<p><b>{{post.post_title}}</b> by {{post.author}} dated {{post.pub_date}}</p>
<p> {{ post.post_body }} </p>
{% if post.reply_chain != NULL %}
<p> {% include "replychain_listing.html" with reply=post.reply_chain %} </p>
{% endif %}
{{ value|linebreaks }}
{% endfor %}
</p>
\ No newline at end of file
<p>Reply by {{reply.author}} dated {{reply.pub_date}}</p>
<p>{{reply.reply_body}}</p>
{% if reply.reply_chain != NULL %}
<p>{% include "replychain_listing.html" with reply=reply.reply_chain %}</p>
{% endif %}
\ No newline at end of file
from django.shortcuts import render from django.shortcuts import render
from django.http import HttpResponse from django.http import HttpResponse
from .models import Post, Reply
# Create your views here. # Create your views here.
def show_forum_page(request): def show_forum_page(request):
return HttpResponse("Welcome to Widget's Forum!") posts = Post.objects.all()
\ No newline at end of file return render(request, 'post_listing.html', {'posts': posts})
\ No newline at end of file
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