Commit ff2d0042 authored by Eugene Ezekiel P. Tan's avatar Eugene Ezekiel P. Tan

Merge branch 'Tan/Forum'

parents f8a7a57f 071be16a
# Generated by Django 4.0.3 on 2022-05-13 03:31
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('Forum', '0002_post_post_author_reply'),
]
operations = [
migrations.AddField(
model_name='post',
name='post_imageUrl',
field=models.CharField(default=1, max_length=999),
),
]
# Generated by Django 4.0.3 on 2022-05-13 03:42
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('Forum', '0003_post_post_imageurl'),
]
operations = [
migrations.AddField(
model_name='reply',
name='reply_post',
field=models.ForeignKey(default=1, on_delete=django.db.models.deletion.CASCADE, to='Forum.post'),
),
]
...@@ -7,10 +7,18 @@ class Post(models.Model): ...@@ -7,10 +7,18 @@ class Post(models.Model):
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) post_author = models.ForeignKey(WidgetUser, on_delete=models.CASCADE, default=1)
post_imageUrl = models.CharField(max_length=999, default = 1)
def __str__(self):
return self.post_title
class Reply(models.Model): class Reply(models.Model):
reply_body = models.CharField(max_length=50) reply_body = models.CharField(max_length=50)
pub_date = models.DateTimeField("date published") pub_date = models.DateTimeField("date published")
reply_author = models.ForeignKey(WidgetUser, on_delete=models.CASCADE, default=1) reply_author = models.ForeignKey(WidgetUser, on_delete=models.CASCADE, default=1)
reply_post = models.ForeignKey(Post, on_delete=models.CASCADE, default=1)
def __str__(self):
thing = self.reply_body + " by " + self.reply_author.last_name + " @ " + self.reply_post.post_title
return thing
h1 {
font-family: 'Courier New', Courier, monospace;
}
h3 {
font-family: 'Courier New', Courier, monospace;
border: 2px solid black;
background-color: azure;
}
body {
background-color: bisque;
}
ul {
font-family: 'Franklin Gothic Medium', 'Arial Narrow', Arial, sans-serif;
list-style-type: square;
border: 5px solid black;
background-color: aliceblue;
}
img {
max-width: 500px;
}
\ No newline at end of file
{% load static %}
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" type="text/css" href="{% static 'Forum/style.css' %}">
<title></title>
</head>
<body>
{% block content %}
{% endblock %}
</body>
</html>
\ No newline at end of file
{% extends "Forum/base.html" %}
{% block content %}
<h1>{{post.post_title}}</h1>
<h4>{{post.post_author.first_name}} {{post.post_author.last_name}}, {{post.pub_date.day}}/{{post.pub_date.month}}/{{post.pub_date.year}}</h4>
<h3>{{post.post_body}}</h3>
<img src= {{post.post_imageUrl}}>
<ul>
{% for reply in reply_list %}
{% if reply.reply_post.post_title == post.post_title %}
<li><u>Reply by {{reply.reply_author.first_name}} {{reply.reply_author.last_name}} dated {{reply.pub_date.day}}/{{reply.pub_date.month}}/{{reply.pub_date.year}}:</u> <br>
{{reply.reply_body}}</li>
</br>
{% endif %}
{% endfor %}
</ul>
{% endblock %}
\ No newline at end of file
{% extends "Forum/base.html" %}
{% block content %}
<h1>Welcome to the Widget's Forum!</h1>
{% if post_list %}
<ul>
{% for post in post_list %}
<h3><li><a href ="{% url 'post' post.id %}">{{post.post_title}}</a>
</br> by {{post.post_author.first_name}} {{post.post_author.last_name}} dated {{post.pub_date.day}}/{{post.pub_date.month}}/{{post.pub_date.year}}</li></h3>
{% endfor %}
</ul>
{% else %}
<p>No posts available.</p>
{% endif %}
{% endblock %}
\ 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
...@@ -3,6 +3,6 @@ from django.urls import path ...@@ -3,6 +3,6 @@ from django.urls import path
from . import views from . import views
urlpatterns = [ urlpatterns = [
path('', views.index, name='index') path('', views.index, name='index'),
path("<int:post_id>/details/", views.posts, name='post')
] ]
...@@ -3,16 +3,22 @@ from . models import Post, Reply ...@@ -3,16 +3,22 @@ from . models import Post, Reply
from homepage.models import WidgetUser from homepage.models import WidgetUser
from django.shortcuts import render from django.shortcuts import render
# Create your views here.
def index(request): def index(request):
# create a dictionary to pass
# data to the template
Posts = Post.objects.all() Posts = Post.objects.all()
Replies = Reply.objects.all() Replies = Reply.objects.all()
post_list = Post.objects.order_by("-pub_date")
context ={ context ={
'Post':Posts, 'Post':Posts,
'Reply':Replies 'Reply':Replies,
'post_list':post_list
} }
# return response with template and context return render(request, "Forum/view.html", context)
def posts(request, post_id):
reply_list = Reply.objects.order_by("-pub_date")
try:
post = Post.objects.get(pk=post_id)
except Post.DoesNotExist:
raise Http404("post doesnt exist")
return render(request,"Forum/post.html",{"post": post, 'reply_list':reply_list})
return render(request, "view.html", context)
# Generated by Django 4.0.3 on 2022-04-04 16:53
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('assignments', '0002_alter_assignment_description_alter_assignment_name'),
]
operations = [
migrations.CreateModel(
name='Course',
fields=[
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('course_code', models.CharField(max_length=10)),
('course_title', models.CharField(max_length=100)),
('section', models.CharField(max_length=3)),
],
),
migrations.AddField(
model_name='assignment',
name='passing_score',
field=models.IntegerField(blank=True, editable=False, null=True),
),
migrations.AddField(
model_name='assignment',
name='course',
field=models.ForeignKey(default='1', on_delete=django.db.models.deletion.CASCADE, to='assignments.course'),
),
]
# Generated by Django 4.0.3 on 2022-05-13 03:31
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('assignments', '0003_course_assignment_passing_score_assignment_course'),
]
operations = [
migrations.AlterField(
model_name='assignment',
name='course',
field=models.ForeignKey(blank=True, default=None, null=True, on_delete=django.db.models.deletion.CASCADE, to='assignments.course'),
),
]
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