Commit 69139449 authored by nekopilar's avatar nekopilar

Fixed URLs of project and forum

parent 40891a4a
# Generated by Django 4.0.3 on 2022-05-23 15:27
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('forum', '0004_post_post_pic'),
]
operations = [
migrations.AlterField(
model_name='post',
name='post_pic',
field=models.ImageField(blank=True, null=True, upload_to='media/forum'),
),
]
...@@ -7,7 +7,7 @@ class Post(models.Model): ...@@ -7,7 +7,7 @@ class Post(models.Model):
post_body = models.TextField() post_body = models.TextField()
pub_date = models.DateField(auto_now_add=True) pub_date = models.DateField(auto_now_add=True)
author = models.ForeignKey(WidgetUser, on_delete=models.CASCADE, null=True) author = models.ForeignKey(WidgetUser, on_delete=models.CASCADE, null=True)
post_pic = models.FileField(upload_to="uploads", null=True, blank=True) post_pic = models.ImageField(upload_to="media/forum", null=True, blank=True)
class Reply(models.Model): class Reply(models.Model):
reply_body = models.TextField() reply_body = models.TextField()
......
...@@ -16,3 +16,16 @@ ...@@ -16,3 +16,16 @@
.post-link:hover { .post-link:hover {
margin-left: 20px; margin-left: 20px;
} }
.new-post-link {
text-decoration: none;
font-family: Khula;
color: black;
font-size: 26px;
padding: 10px;
width: fit-content;
transition: 0.2s ease-in-out;
}
.new-post-link:hover {
background-color: rgba(0, 0, 0, 0.8);
color: white;
}
\ No newline at end of file
label {
font-family: Khula;
font-weight: 600;
}
input {
font-family: Khula;
}
p {
margin: 30px 0px;
}
form {
padding-bottom: 20px;
}
\ No newline at end of file
...@@ -26,4 +26,5 @@ Welcome to Widget's Forum! ...@@ -26,4 +26,5 @@ Welcome to Widget's Forum!
</li> </li>
{% endfor %} {% endfor %}
</ul> </ul>
<a class="new-post-link" href="/posts/add">New Forum Post</a>
{% endblock %} {% endblock %}
\ No newline at end of file
...@@ -13,7 +13,11 @@ ...@@ -13,7 +13,11 @@
{% endblock %} {% endblock %}
{% block content %} {% block content %}
{% if object.post_pic != None and object.post_pic != '' %}
<img width=1000 height=200 src="{% get_media_prefix %}{{object.post_pic}}"/>
{% else %}
<img width=1000 height=200 src="{% static 'forum/default_forumpic.png' %}"/> <img width=1000 height=200 src="{% static 'forum/default_forumpic.png' %}"/>
{% endif %}
<p class="post-author"> by {{object.author.first_name}} {{object.author.last_name}}, {{object.pub_date | date:"d/m/o"}}</p> <p class="post-author"> by {{object.author.first_name}} {{object.author.last_name}}, {{object.pub_date | date:"d/m/o"}}</p>
<p>{{object.post_body}}</p> <p>{{object.post_body}}</p>
<ul> <ul>
......
<!-- forum/post_form.html -->
{% extends 'base.html' %}
{% load static %}
{% block title %}Forum{% endblock %}
{% block styles %}
<link rel="stylesheet" href="{% static 'forum/post_form.css' %}">
{% endblock %}
{% block header %}
Add Post
{% endblock %}
{% block content %}
<form enctype="multipart/form-data" method="post">
{% csrf_token %}
{{ form.as_p }}
<input type="submit" value="Save Post">
</form>
{% endblock %}
\ No newline at end of file
from django.shortcuts import render from django.shortcuts import render
from django.views import View from django.views import View
from django.views.generic.detail import DetailView from django.views.generic.detail import DetailView
from django.views.generic.edit import CreateView
from .models import Post, Reply from .models import Post, Reply
...@@ -20,3 +21,9 @@ class ForumDetailView(DetailView): ...@@ -20,3 +21,9 @@ class ForumDetailView(DetailView):
return context return context
class PostCreateView(CreateView):
model = Post
fields = ["post_body", "post_title", "author", "post_pic"]
def get_success_url(self):
return "/forum/"
\ No newline at end of file
...@@ -18,11 +18,15 @@ from django.urls import path, include ...@@ -18,11 +18,15 @@ from django.urls import path, include
from django.conf.urls.static import static from django.conf.urls.static import static
from django.conf import settings from django.conf import settings
from homepage.views import WidgetUserCreateView from homepage.views import WidgetUserCreateView
from forum.views import PostCreateView
urlpatterns = [ urlpatterns = [
path('homepage/', include("homepage.urls", namespace='homepage')), path('homepage/', include("homepage.urls", namespace='homepage')),
path('users/add', WidgetUserCreateView.as_view(), path('users/add', WidgetUserCreateView.as_view(),
name='widgetuser_form'), name='widgetuser_form'),
path('posts/add', PostCreateView.as_view(),
name='post_form'),
path('admin/', admin.site.urls), path('admin/', admin.site.urls),
path('forum/', include("forum.urls", namespace='forum')), path('forum/', include("forum.urls", namespace='forum')),
path('announcements/', include("announcement_board.urls", path('announcements/', include("announcement_board.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