Commit ab912595 authored by Ray Rafael Abenido's avatar Ray Rafael Abenido

New Feature/Fix: image uploading issue resolved. Ready for merge with master branch.

parent 702d2c3d
# Generated by Django 3.2.12 on 2022-05-26 13:19
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('forum', '0005_auto_20220524_1522'),
]
operations = [
migrations.AlterField(
model_name='post',
name='post_image',
field=models.ImageField(null=True, upload_to='images/'),
),
]
# Generated by Django 3.2.12 on 2022-05-26 13:24
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('forum', '0006_alter_post_post_image'),
]
operations = [
migrations.AlterField(
model_name='post',
name='post_image',
field=models.ImageField(null=True, upload_to='image/'),
),
]
# Generated by Django 3.2.12 on 2022-05-26 13:25
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('forum', '0007_alter_post_post_image'),
]
operations = [
migrations.AlterField(
model_name='post',
name='post_image',
field=models.ImageField(null=True, upload_to='images/'),
),
]
# Generated by Django 3.2.12 on 2022-05-26 13:37
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('forum', '0008_alter_post_post_image'),
]
operations = [
migrations.AlterField(
model_name='post',
name='post_image',
field=models.ImageField(null=True, upload_to='static/images'),
),
]
# Generated by Django 3.2.12 on 2022-05-26 13:41
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('forum', '0009_alter_post_post_image'),
]
operations = [
migrations.AlterField(
model_name='post',
name='post_image',
field=models.ImageField(null=True, upload_to='static/images/'),
),
]
# Generated by Django 3.2.12 on 2022-05-26 13:47
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('forum', '0010_alter_post_post_image'),
]
operations = [
migrations.AlterField(
model_name='post',
name='post_image',
field=models.ImageField(null=True, upload_to='images\\'),
),
]
# Generated by Django 3.2.12 on 2022-05-26 13:55
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('forum', '0011_alter_post_post_image'),
]
operations = [
migrations.AlterField(
model_name='post',
name='post_image',
field=models.ImageField(null=True, upload_to=''),
),
]
# Generated by Django 3.2.12 on 2022-05-26 14:03
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('forum', '0012_alter_post_post_image'),
]
operations = [
migrations.AlterField(
model_name='post',
name='post_image',
field=models.ImageField(null=True, upload_to='images/'),
),
]
# Generated by Django 3.2.12 on 2022-05-26 14:04
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('forum', '0013_alter_post_post_image'),
]
operations = [
migrations.AlterField(
model_name='post',
name='post_image',
field=models.ImageField(null=True, upload_to=''),
),
]
# Generated by Django 3.2.12 on 2022-05-26 14:11
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('forum', '0014_alter_post_post_image'),
]
operations = [
migrations.AlterField(
model_name='post',
name='post_image',
field=models.FileField(null=True, upload_to=''),
),
]
# Generated by Django 3.2.12 on 2022-05-26 14:12
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('forum', '0015_alter_post_post_image'),
]
operations = [
migrations.AlterField(
model_name='post',
name='post_image',
field=models.FileField(null=True, upload_to='images/'),
),
]
# Generated by Django 3.2.12 on 2022-05-26 14:18
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('forum', '0016_alter_post_post_image'),
]
operations = [
migrations.AlterField(
model_name='post',
name='post_image',
field=models.ImageField(null=True, upload_to='images/'),
),
]
# Generated by Django 3.2.12 on 2022-05-27 02:04
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('forum', '0017_alter_post_post_image'),
]
operations = [
migrations.AlterField(
model_name='post',
name='post_image',
field=models.ImageField(null=True, upload_to=''),
),
]
......@@ -4,7 +4,7 @@ from django.db import models
# Create your models here.
class Post(models.Model):
author = models.ForeignKey('homepage.WidgetUser', on_delete=models.CASCADE)
post_image = models.ImageField(null=True)
post_image = models.ImageField(null=True, upload_to='')
post_title = models.CharField(max_length=100)
post_body = models.TextField()
pub_date = models.DateTimeField(auto_now_add=True, null=True)
......
{% extends 'forum/base.html' %}
{% block content %}
<p> Nice </p>
<p> New Post added! </p>
<p><a href="{% url 'Show Forum Page' %}">Return to Forum page</a></p>
{% endblock %}
\ No newline at end of file
......@@ -2,7 +2,7 @@
{% block content %}
<h2> New Forum Post: </h2>
<form action="{% url 'Add New Post' %}" method="POST">
<form action="{% url 'Show Confirmation' %}" method="POST" enctype="multipart/form-data">
{% csrf_token %}
<!-- POST TITLE -->
......
from django.urls import path
from . import views
from .views import CreateNewPost
urlpatterns = [
path('', views.show_index, name="Show Forum Page"),
path('post/<int:post_id>/details', views.show_post, name="Show Post Details"),
path('posts/add', views.show_form, name="Show Add Post"),
path('posts/add/success', views.add_new_post, name="Add New Post")
# Disabled for the time being. May be used again in the near future.
#path('post/add', views.show_form, name="Add Post Form"),
#path('post/confirmation', views.show_confirmation, name="Show confirmation"),
path('posts/add', CreateNewPost.show_form, name="Show Add Post"),
path('post/add/success', CreateNewPost.add_new_post, name="Show Confirmation"),
]
\ No newline at end of file
......@@ -5,6 +5,8 @@
# importing from django
from django.shortcuts import render
from django.http import Http404, HttpResponse
from django.views import View
from django.core.files.storage import FileSystemStorage
# importing from other apps in project
from .models import Post, Reply
......@@ -32,32 +34,30 @@ def show_post(request, post_id):
replies = Reply.objects.filter(post=post_id).order_by("-pub_date")
return render(request, 'forum/post_details.html', {'post':post, 'replies': replies})
# for showing form where users can add new posts.
def show_form(request):
users = WidgetUser.objects.all()
return render(request, 'forum/post_form.html', {'users':users})
# for adding a new post to database, then returning back to reply list
def add_new_post(request):
title = request.POST.get("post_title")
body = request.POST.get("post_body")
author = request.POST.get("post_author")
image = request.POST.get("post_image")
current_date = datetime.datetime.now()
new_post = Post.objects.create(post_title=title, post_body=body,author_id=author,
post_image=image,pub_date=current_date)
class CreateNewPost(View):
# for adding a new post to database, then returning back to reply list
def show_form(request):
users = WidgetUser.objects.all()
return render(request, 'forum/post_form.html', {'users':users})
posts = Post.objects.all().order_by("-pub_date")
return render(request, 'forum/index.html', {'posts':posts})
# =================================
# UNUSED FUNCTIONS BUT NOT DEPRECATED
# =================================
def show_confirmation(request):
if (request.method == "POST"):
# for showing form where users can add new posts.
def add_new_post(request):
# populate new record
title = request.POST.get("post_title")
body = request.POST.get("post_body")
author = request.POST.get("author_id")
post = Post.objects.create(post_title=title,post_body=body,author_id=author)
return HttpResponse("Article saved!")
\ No newline at end of file
author = request.POST.get("post_author")
image = request.FILES['post_image']
current_date = datetime.datetime.now()
new_post = Post.objects.create(post_title=title, post_body=body,author_id=author,
post_image=image,pub_date=current_date)
#upload file into static\images folder
fss = FileSystemStorage()
file = fss.save(image.name, image)
return render(request, 'forum/confirmation.html', {})
h1 {
color: palevioletred;
font-weight: bold;
}
h2 {
color: palevioletred;
font-weight: bold;
}
h3 {
color: palevioletred;
font-weight: bold;
}
ol {
color: wheat;
font-weight: bold;
}
ul {
color: wheat;
font-weight: bold;
}
body {
background-color: black;
}
a {
color: yellow;
}
\ 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