Commit 2c12061b authored by Eugene Ezekiel P. Tan's avatar Eugene Ezekiel P. Tan

Merge branch 'Tan/Forum' & pyc conflicts

parents 13f71a47 4d3f3e72
from django.forms import ModelForm
from .models import Post
class PostForm(ModelForm):
class Meta:
model = Post
fields = ["post_title", "post_body", "post_author", "post_imageUrl"]
\ No newline at end of file
# Generated by Django 4.0.3 on 2022-05-25 08:35
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('Forum', '0004_reply_reply_post'),
]
operations = [
migrations.AlterField(
model_name='post',
name='pub_date',
field=models.DateTimeField(auto_now_add=True, verbose_name='date published'),
),
]
# Generated by Django 4.0.3 on 2022-05-25 08:38
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('Forum', '0005_alter_post_pub_date'),
]
operations = [
migrations.AlterField(
model_name='post',
name='post_imageUrl',
field=models.CharField(max_length=999, null=True),
),
]
......@@ -5,9 +5,9 @@ from homepage.models import WidgetUser
class Post(models.Model):
post_title = models.CharField(max_length=50)
post_body = models.CharField(max_length=500)
pub_date = models.DateTimeField("date published")
pub_date = models.DateTimeField("date published", auto_now_add=True)
post_author = models.ForeignKey(WidgetUser, on_delete=models.CASCADE, default=1)
post_imageUrl = models.CharField(max_length=999, default = 1)
post_imageUrl = models.CharField(max_length=999, null=True)
def __str__(self):
return self.post_title
......
{% extends "Forum/base.html" %}
{% block content %}
<h1>Contribute a new post to the Epic Gamer Forums</h1>
<form action="{% url 'Forum:index' %}">
<button type="submit">Go Back</button>
</form>
<form method="POST" action= "{% url 'Forum:addPost' %}">
{% csrf_token %}
{{post_Form.as_p}}
<button class="button" type="submit">Submit Post</button>
</form>
{% endblock %}
\ No newline at end of file
......@@ -2,6 +2,10 @@
{% block content %}
<form action="{% url 'Forum:index' %}">
<button type="submit">Go Back</button>
</form>
<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>
......@@ -9,6 +13,7 @@
<img src= {{post.post_imageUrl}}>
<ul>
<h4> Replies:</h4>
{% for reply in reply_list %}
{% if reply.reply_post.post_title == post.post_title %}
......@@ -21,4 +26,5 @@
{% endfor %}
</ul>
{% endblock %}
\ No newline at end of file
{% extends "Forum/base.html" %}
{% block content %}
<h1>Welcome to the Widget's Forum!</h1>
<h1>Welcome to the Epic Gamers Forum!</h1>
{% if post_list %}
<ul>
{% for post in post_list %}
<h3><li><a href ="{% url 'post' post.id %}">{{post.post_title}}</a>
<h3><li><a href ="{% url 'Forum: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>
......@@ -13,4 +14,8 @@
<p>No posts available.</p>
{% endif %}
<form action="{% url 'Forum:addPost' %}">
<button type="submit">New Forum Post</button>
</form>
{% endblock %}
\ No newline at end of file
......@@ -2,7 +2,12 @@ from django.urls import path
from . import views
app_name = "Forum"
urlpatterns = [
#forum home page
path('', views.index, name='index'),
path("<int:post_id>/details/", views.posts, name='post')
#forum posts
path("<int:post_id>/details/", views.posts, name='post'),
#making new forum posts
path("posts/add/", views.newPost,name= 'addPost')
]
from django.http import HttpResponse
import Forum
from .forms import PostForm
from . models import Post, Reply
from homepage.models import WidgetUser
from django.shortcuts import render
from django.shortcuts import render, redirect
def index(request):
Posts = Post.objects.all()
......@@ -22,3 +24,16 @@ def posts(request, post_id):
raise Http404("post doesnt exist")
return render(request,"Forum/post.html",{"post": post, 'reply_list':reply_list})
def newPost(request):
post_Form = PostForm()
if request.method == "POST":
post_Form = PostForm(request.POST)
if post_Form.is_valid():
post_Form.save()
return redirect("Forum:addPost")
else:
post_Form = PostForm()
return render(request, "Forum/addPost.html", {"post_Form":post_Form})
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