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 ...@@ -4,7 +4,7 @@ from django.db import models
# Create your models here. # Create your models here.
class Post(models.Model): class Post(models.Model):
author = models.ForeignKey('homepage.WidgetUser', on_delete=models.CASCADE) 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_title = models.CharField(max_length=100)
post_body = models.TextField() post_body = models.TextField()
pub_date = models.DateTimeField(auto_now_add=True, null=True) pub_date = models.DateTimeField(auto_now_add=True, null=True)
......
{% extends 'forum/base.html' %} {% extends 'forum/base.html' %}
{% block content %} {% block content %}
<p> Nice </p> <p> New Post added! </p>
<p><a href="{% url 'Show Forum Page' %}">Return to Forum page</a></p>
{% endblock %} {% endblock %}
\ No newline at end of file
...@@ -2,7 +2,7 @@ ...@@ -2,7 +2,7 @@
{% block content %} {% block content %}
<h2> New Forum Post: </h2> <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 %} {% csrf_token %}
<!-- POST TITLE --> <!-- POST TITLE -->
......
from django.urls import path from django.urls import path
from . import views from . import views
from .views import CreateNewPost
urlpatterns = [ urlpatterns = [
path('', views.show_index, name="Show Forum Page"), path('', views.show_index, name="Show Forum Page"),
path('post/<int:post_id>/details', views.show_post, name="Show Post Details"), 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', CreateNewPost.show_form, name="Show Add Post"),
path('posts/add/success', views.add_new_post, name="Add New Post") path('post/add/success', CreateNewPost.add_new_post, name="Show Confirmation"),
# 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"),
] ]
\ No newline at end of file
...@@ -5,6 +5,8 @@ ...@@ -5,6 +5,8 @@
# importing from django # importing from django
from django.shortcuts import render from django.shortcuts import render
from django.http import Http404, HttpResponse from django.http import Http404, HttpResponse
from django.views import View
from django.core.files.storage import FileSystemStorage
# importing from other apps in project # importing from other apps in project
from .models import Post, Reply from .models import Post, Reply
...@@ -32,32 +34,30 @@ def show_post(request, post_id): ...@@ -32,32 +34,30 @@ def show_post(request, post_id):
replies = Reply.objects.filter(post=post_id).order_by("-pub_date") replies = Reply.objects.filter(post=post_id).order_by("-pub_date")
return render(request, 'forum/post_details.html', {'post':post, 'replies': replies}) return render(request, 'forum/post_details.html', {'post':post, 'replies': replies})
# for showing form where users can add new posts. class CreateNewPost(View):
def show_form(request): # for adding a new post to database, then returning back to reply list
users = WidgetUser.objects.all() def show_form(request):
return render(request, 'forum/post_form.html', {'users':users}) 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)
posts = Post.objects.all().order_by("-pub_date") # for showing form where users can add new posts.
return render(request, 'forum/index.html', {'posts':posts}) def add_new_post(request):
# populate new record
# =================================
# UNUSED FUNCTIONS BUT NOT DEPRECATED
# =================================
def show_confirmation(request):
if (request.method == "POST"):
title = request.POST.get("post_title") title = request.POST.get("post_title")
body = request.POST.get("post_body") body = request.POST.get("post_body")
author = request.POST.get("author_id") author = request.POST.get("post_author")
post = Post.objects.create(post_title=title,post_body=body,author_id=author) image = request.FILES['post_image']
return HttpResponse("Article saved!") current_date = datetime.datetime.now()
\ No newline at end of file
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