Commit 48ec8443 authored by Eugene Ezekiel P. Tan's avatar Eugene Ezekiel P. Tan

Stable build of Forums with Midterm functionality

parent 139fb9f7
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 4.0.3 on 2022-04-04 14:20
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('homepage', '0002_widgetuser_email_widgetuser_id_num_department'),
('Forum', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='post',
name='post_author',
field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to='homepage.widgetuser'),
),
migrations.CreateModel(
name='Reply',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('reply_body', models.CharField(max_length=50)),
('pub_date', models.DateTimeField(verbose_name='date published')),
('reply_author', models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to='homepage.widgetuser')),
],
),
]
from django.db import models from django.db import models
from homepage.models import WidgetUser
# Create your models here. # Create your models here.
class Post(models.Model): class Post(models.Model):
post_title = models.CharField(max_length=50) post_title = models.CharField(max_length=50)
post_body = models.CharField(max_length=500) post_body = models.CharField(max_length=500)
pub_date = models.DateTimeField("date published") pub_date = models.DateTimeField("date published")
post_author = models.ForeignKey(WidgetUser, on_delete=models.CASCADE, default=1)
class Reply(models.Model):
reply_body = models.CharField(max_length=50)
pub_date = models.DateTimeField("date published")
reply_author = models.ForeignKey(WidgetUser, on_delete=models.CASCADE, default=1)
\ No newline at end of file
<!DOCTYPE html>
<html lang="en">
<body>
<h1>~~~Forums Posts~~~</h1>
{% for Post in Post %}
<h4>{{Post.post_title}} by {{Post.post_author.first_name}} {{Post.post_author.last_name}} dated {{Post.pub_date}}</h4>
{{Post.post_body}}
<br></br>
{% endfor %}
<br></br>
{% for Reply in Reply%}
<u>Reply by {{Reply.reply_author.first_name}} {{Reply.reply_author.last_name}} dated {{Reply.pub_date}}:</u> <br>
{{Reply.reply_body}}
<br></br>
{% endfor %}
</body>
</html>
\ No newline at end of file
from django.http import HttpResponse from django.http import HttpResponse
from . models import Post, Reply
from homepage.models import WidgetUser
from django.shortcuts import render
# Create your views here. # Create your views here.
def index(request): def index(request):
return HttpResponse("This is the Forumz!") # create a dictionary to pass
# data to the template
Posts = Post.objects.all()
Replies = Reply.objects.all()
context ={
'Post':Posts,
'Reply':Replies
}
# return response with template and context
return render(request, "view.html", context)
No preview for this file type
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