Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
widget_someone here is possessed by an owl
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
Laetitia de Castro
widget_someone here is possessed by an owl
Commits
e44b4009
Commit
e44b4009
authored
May 26, 2022
by
Rurik Serzo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Added add post form
parent
c6f0bfa1
Changes
10
Show whitespace changes
Inline
Side-by-side
Showing
10 changed files
with
46 additions
and
5 deletions
+46
-5
db.sqlite3
db.sqlite3
+0
-0
forms.cpython-310.pyc
forum/__pycache__/forms.cpython-310.pyc
+0
-0
urls.cpython-310.pyc
forum/__pycache__/urls.cpython-310.pyc
+0
-0
views.cpython-310.pyc
forum/__pycache__/views.cpython-310.pyc
+0
-0
forms.py
forum/forms.py
+7
-0
new_post.html
forum/templates/forum/new_post.html
+20
-0
post_detail.html
forum/templates/forum/post_detail.html
+1
-1
urls.py
forum/urls.py
+3
-2
views.py
forum/views.py
+13
-2
forum.css
static/forum.css
+2
-0
No files found.
db.sqlite3
View file @
e44b4009
No preview for this file type
forum/__pycache__/forms.cpython-310.pyc
0 → 100644
View file @
e44b4009
File added
forum/__pycache__/urls.cpython-310.pyc
View file @
e44b4009
No preview for this file type
forum/__pycache__/views.cpython-310.pyc
View file @
e44b4009
No preview for this file type
forum/forms.py
0 → 100644
View file @
e44b4009
from
django.forms
import
ModelForm
from
.models
import
Post
class
PostForm
(
ModelForm
):
class
Meta
:
model
=
Post
fields
=
[
"post_title"
,
"post_body"
,
"author"
]
\ No newline at end of file
forum/templates/forum/new_post.html
0 → 100644
View file @
e44b4009
{% extends 'base.html' %}
{% load static %}
{% block title %}Forum{% endblock %}
{% block styles %}
<link
rel=
"stylesheet"
href=
"{% static 'forum.css' %}"
>
{% endblock %}
{% block content %}
<h1>
New Forum Post
</h1>
<form
action=
"{% url 'forum:new-post' %}"
method=
"POST"
>
{% csrf_token %}
{{ post_form.as_p }}
<button
class=
"button-style"
type=
"submit"
>
Save Post
</button>
</form>
<button
class=
"button-style"
><a
href=
"/forum"
>
Back to Forum
</a></button>
{% endblock %}
\ No newline at end of file
forum/templates/forum/post_detail.html
View file @
e44b4009
...
@@ -20,7 +20,7 @@
...
@@ -20,7 +20,7 @@
<img
src=
"{% static 'post1.jpg' %}"
alt=
"Leni Robredo"
>
<img
src=
"{% static 'post1.jpg' %}"
alt=
"Leni Robredo"
>
{% elif post.id == 2 %}
{% elif post.id == 2 %}
<img
src=
"{% static 'post2.jpg' %}"
alt=
"Lady Gaga MET camp"
>
<img
src=
"{% static 'post2.jpg' %}"
alt=
"Lady Gaga MET camp"
>
{% el
se
%}
{% el
if post.id == 3
%}
<img
src=
"{% static 'post3.jpg' %}"
alt=
"Bruno Mars Grammys 2022"
>
<img
src=
"{% static 'post3.jpg' %}"
alt=
"Bruno Mars Grammys 2022"
>
{% endif %}
{% endif %}
...
...
forum/urls.py
View file @
e44b4009
from
django.urls
import
path
from
django.urls
import
path
from
.views
import
index
,
PostDetailView
from
.views
import
index
,
PostDetailView
,
new_post
urlpatterns
=
[
urlpatterns
=
[
path
(
""
,
index
,
name
=
"index"
),
path
(
""
,
index
,
name
=
"index"
),
path
(
"<int:pk>/details"
,
PostDetailView
.
as_view
(),
name
=
"post-detail"
)
path
(
"<int:pk>/details"
,
PostDetailView
.
as_view
(),
name
=
"post-detail"
),
path
(
"add"
,
new_post
,
name
=
"new-post"
)
]
]
app_name
=
"Forum"
app_name
=
"Forum"
forum/views.py
View file @
e44b4009
from
django.shortcuts
import
render
from
django.shortcuts
import
render
,
redirect
from
django.http
import
HttpResponse
from
django.http
import
HttpResponse
from
django.template
import
loader
from
django.template
import
loader
from
django.views.generic.detail
import
DetailView
from
django.views.generic.detail
import
DetailView
from
.models
import
Post
,
Reply
from
.models
import
Post
,
Reply
from
.forms
import
PostForm
def
index
(
request
):
def
index
(
request
):
context
=
{
context
=
{
...
@@ -14,3 +15,13 @@ def index(request):
...
@@ -14,3 +15,13 @@ def index(request):
class
PostDetailView
(
DetailView
):
class
PostDetailView
(
DetailView
):
model
=
Post
model
=
Post
def
new_post
(
request
):
if
request
.
method
==
"POST"
:
post_form
=
PostForm
(
request
.
POST
)
if
post_form
.
is_valid
():
post_form
.
save
()
return
redirect
(
"forum:index"
)
else
:
post_form
=
PostForm
()
return
render
(
request
,
'forum/new_post.html'
,
{
"post_form"
:
post_form
})
\ No newline at end of file
static/forum.css
View file @
e44b4009
...
@@ -17,6 +17,8 @@
...
@@ -17,6 +17,8 @@
border
:
3px
solid
blue
;
border
:
3px
solid
blue
;
padding
:
8px
20px
;
padding
:
8px
20px
;
margin-left
:
30px
;
margin-left
:
30px
;
text-decoration
:
underline
;
color
:
blue
;
}
}
.post-list
{
.post-list
{
...
...
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