Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
widgets_FEKK
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
Kyla Martin
widgets_FEKK
Commits
2093cf64
Commit
2093cf64
authored
May 18, 2022
by
Emmanuel Linus T. Evangelista
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
add image upload for Forum
parent
ddcac344
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
38 additions
and
5 deletions
+38
-5
forms.py
WidgetFEKK/Forum/forms.py
+1
-1
0003_post_image.py
WidgetFEKK/Forum/migrations/0003_post_image.py
+19
-0
models.py
WidgetFEKK/Forum/models.py
+11
-0
details.css
WidgetFEKK/Forum/static/Forum/details.css
+0
-1
add.html
WidgetFEKK/Forum/templates/Forum/add.html
+1
-1
details.html
WidgetFEKK/Forum/templates/Forum/details.html
+5
-1
views.py
WidgetFEKK/Forum/views.py
+1
-1
No files found.
WidgetFEKK/Forum/forms.py
View file @
2093cf64
...
...
@@ -4,4 +4,4 @@ from .models import Post
class
PostForm
(
forms
.
ModelForm
):
class
Meta
:
model
=
Post
fields
=
[
'post_title'
,
'post_body'
,
'author'
]
\ No newline at end of file
fields
=
[
'post_title'
,
'post_body'
,
'author'
,
'image'
]
\ No newline at end of file
WidgetFEKK/Forum/migrations/0003_post_image.py
0 → 100644
View file @
2093cf64
# Generated by Django 3.2.12 on 2022-05-18 16:13
import
Forum.models
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'Forum'
,
'0002_auto_20220325_0135'
),
]
operations
=
[
migrations
.
AddField
(
model_name
=
'post'
,
name
=
'image'
,
field
=
models
.
ImageField
(
blank
=
True
,
null
=
True
,
upload_to
=
Forum
.
models
.
filepath
),
),
]
WidgetFEKK/Forum/models.py
View file @
2093cf64
from
django.db
import
models
from
Homepage.models
import
WidgetUser
from
datetime
import
datetime
import
os
def
filepath
(
request
,
filename
):
old_filename
=
filename
time_now
=
datetime
.
now
()
.
strftime
(
"
%
Y
%
m
%
d
%
H:
%
M:
%
S"
)
filename
=
f
"{time_now} {old_filename}"
return
os
.
path
.
join
(
"uploads/"
,
filename
)
# Create your models here.
class
Post
(
models
.
Model
):
post_title
=
models
.
CharField
(
max_length
=
50
)
...
...
@@ -9,6 +18,8 @@ class Post(models.Model):
author
=
models
.
ForeignKey
(
WidgetUser
,
on_delete
=
models
.
CASCADE
,
default
=
1
)
image
=
models
.
ImageField
(
upload_to
=
filepath
,
null
=
True
,
blank
=
True
)
def
__str__
(
self
):
return
self
.
post_title
...
...
WidgetFEKK/Forum/static/Forum/details.css
View file @
2093cf64
...
...
@@ -19,7 +19,6 @@ body {
}
#thumbnail
{
width
:
150px
;
height
:
150px
;
object-fit
:
cover
;
object-position
:
center
;
...
...
WidgetFEKK/Forum/templates/Forum/add.html
View file @
2093cf64
...
...
@@ -23,7 +23,7 @@
<h1>
New Forum Post
</h1>
<form
action=
"/posts/add/"
method=
"post"
>
<form
action=
"/posts/add/"
method=
"post"
enctype=
"multipart/form-data"
>
{% csrf_token %}
{{ form }}
<input
type=
"submit"
id=
"save-post-btn"
value=
"Save Post"
>
...
...
WidgetFEKK/Forum/templates/Forum/details.html
View file @
2093cf64
...
...
@@ -23,7 +23,11 @@
<a
href=
"/forum"
>
Back to all posts
</a>
</div>
<img
id=
"thumbnail"
src=
"{% static 'Forum/thumbnail.jpg' %}"
alt=
"placeholder image"
/>
{% if post.image %}
<img
id=
"thumbnail"
src=
"{{ MEDIA_DIR }}/uploads/{{ post.image }}"
alt=
"thumbnail"
/>
{% else %}
<img
id=
"thumbnail"
src=
"{% static 'Forum/thumbnail.jpg' %}"
alt=
"placeholder image"
/>
{% endif %}
<h1
id=
"title"
>
{{ post.post_title }}
</h1>
<h4
id=
"subtitle"
>
by {{ post.author.first_name }} {{ post.author.last_name }}, {{ post.pub_date|date:"d/m/Y" }}
</h4>
<p
class=
"body-text"
>
{{ post.post_body }}
</p>
...
...
WidgetFEKK/Forum/views.py
View file @
2093cf64
...
...
@@ -22,7 +22,7 @@ class AddForumPostView(View):
return
render
(
request
,
'Forum/add.html'
,
{
'form'
:
PostForm
()})
def
post
(
self
,
request
):
form
=
PostForm
(
request
.
POST
)
form
=
PostForm
(
request
.
POST
,
request
.
FILES
)
if
form
.
is_valid
():
new_post
=
form
.
save
()
return
redirect
(
'/forum'
)
\ No newline at end of file
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment