Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
widget_father when can i be on my own i have the hello world to see
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
father when can i be on my own i have the hello world to see
widget_father when can i be on my own i have the hello world to see
Commits
175beaf3
Commit
175beaf3
authored
May 19, 2022
by
nekopilar
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
created templates for forum and converted views from fbv to cbv
parent
03ddadad
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
44 additions
and
27 deletions
+44
-27
models.py
forum/models.py
+1
-0
index.html
forum/templates/forum/index.html
+29
-0
post_detail.html
forum/templates/forum/post_detail.html
+0
-0
urls.py
forum/urls.py
+3
-2
views.py
forum/views.py
+11
-25
No files found.
forum/models.py
View file @
175beaf3
...
...
@@ -7,6 +7,7 @@ class Post(models.Model):
post_body
=
models
.
TextField
()
pub_date
=
models
.
DateField
(
auto_now_add
=
True
)
author
=
models
.
ForeignKey
(
WidgetUser
,
on_delete
=
models
.
CASCADE
,
null
=
True
)
post_pic
=
models
.
FileField
(
upload_to
=
"uploads"
,
null
=
True
,
blank
=
True
)
class
Reply
(
models
.
Model
):
reply_body
=
models
.
TextField
()
...
...
forum/templates/forum/index.html
0 → 100644
View file @
175beaf3
<!-- forum/index.html -->
{% extends 'base.html' %}
{% load static %}
{% block title %}Announcements{% endblock %}
{% block styles %}
<link
rel=
"stylesheet"
href=
"{% static 'announcement_board/announcement_index.css' %}"
>
{% endblock %}
{% block header %}
Welcome to Widget's Forum!
{% endblock %}
{% block content %}
<p
class=
"banner-text"
>
Forum posts:
</p>
<ul>
{% for post in all_posts %}
<li>
<a
class=
"post-link"
href=
"{{post.id}}/details"
>
{{post.post_title}} by
{{post.author.first_name}},
{{post.author.last_name}} dated
{{post.pub_date | date:"d/m/o"}}
</a>
</br>
</li>
{% endfor %}
</ul>
{% endblock %}
\ No newline at end of file
forum/templates/forum/post_detail.html
0 → 100644
View file @
175beaf3
forum/urls.py
View file @
175beaf3
from
django.urls
import
path
from
.views
import
index
from
.views
import
ForumView
,
ForumDetailView
urlpatterns
=
[
path
(
''
,
index
,
name
=
'index'
),
path
(
''
,
ForumView
.
as_view
(),
name
=
'index'
),
path
(
'<int:pk>/details'
,
ForumDetailView
.
as_view
(),
name
=
'index'
),
]
app_name
=
"forum"
\ No newline at end of file
forum/views.py
View file @
175beaf3
from
django.shortcuts
import
render
from
django.http
import
HttpResponse
from
django.views
import
View
from
django.views.generic.detail
import
DetailView
from
.models
import
Post
,
Reply
# View for forum page
def
index
(
request
):
return
HttpResponse
(
display_forumposts
(
Post
.
objects
.
all
(),
Reply
.
objects
.
all
()))
class
ForumView
(
View
):
def
get
(
self
,
request
):
objects_set
=
{
"all_posts"
:
[
obj
for
obj
in
Post
.
objects
.
all
()]
}
return
render
(
request
,
'forum/index.html'
,
objects_set
)
def
display_forumposts
(
post_data
,
reply_data
):
display_output
=
"FORUM POSTS: <br>"
for
object
in
post_data
:
post_title
=
object
.
post_title
post_first_name
=
object
.
author
.
first_name
post_last_name
=
object
.
author
.
last_name
post_pub_date
=
str
(
object
.
pub_date
)
post_body
=
object
.
post_body
reply_objects
=
Reply
.
objects
.
filter
(
post_id
=
object
.
id
)
.
all
()
display_output
+=
f
'''
{post_title} by {post_first_name} {post_last_name} dated {post_pub_date}:<br>
{post_body}<br>
'''
for
objects
in
reply_objects
:
display_output
+=
f
'''
Reply by {objects.author.first_name} {objects.author.last_name} dated {objects.pub_date}:<br>
{objects.reply_body}<br>
'''
display_output
+=
"<br>"
return
display_output
class
ForumDetailView
(
DetailView
):
model
=
Post
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