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
eecd1b6e
Commit
eecd1b6e
authored
Apr 03, 2022
by
Rurik Serzo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Created the formatting for forum view
parent
eec7efe8
Changes
4
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
34 additions
and
2 deletions
+34
-2
models.cpython-39.pyc
forum/__pycache__/models.cpython-39.pyc
+0
-0
views.cpython-39.pyc
forum/__pycache__/views.cpython-39.pyc
+0
-0
models.py
forum/models.py
+21
-1
views.py
forum/views.py
+13
-1
No files found.
forum/__pycache__/models.cpython-39.pyc
View file @
eecd1b6e
No preview for this file type
forum/__pycache__/views.cpython-39.pyc
View file @
eecd1b6e
No preview for this file type
forum/models.py
View file @
eecd1b6e
...
@@ -8,8 +8,28 @@ class Post(models.Model):
...
@@ -8,8 +8,28 @@ class Post(models.Model):
pub_date
=
models
.
DateField
(
auto_now_add
=
True
)
pub_date
=
models
.
DateField
(
auto_now_add
=
True
)
author
=
models
.
ForeignKey
(
WidgetUser
,
on_delete
=
models
.
CASCADE
,
null
=
True
)
author
=
models
.
ForeignKey
(
WidgetUser
,
on_delete
=
models
.
CASCADE
,
null
=
True
)
def
__str__
(
self
):
return
self
.
post_title
def
getPost
(
self
):
return
"{} by {} {} dated {}:<br>{}<br>"
.
format
(
self
.
post_title
,
self
.
author
.
first_name
,
self
.
author
.
last_name
,
self
.
pub_date
,
self
.
post_body
)
class
Reply
(
models
.
Model
):
class
Reply
(
models
.
Model
):
reply_body
=
models
.
TextField
()
reply_body
=
models
.
TextField
()
pub_date
=
models
.
DateField
(
auto_now_add
=
True
)
pub_date
=
models
.
DateField
(
auto_now_add
=
True
)
author
=
models
.
ForeignKey
(
WidgetUser
,
on_delete
=
models
.
CASCADE
,
null
=
True
)
author
=
models
.
ForeignKey
(
WidgetUser
,
on_delete
=
models
.
CASCADE
,
null
=
True
)
post
=
models
.
ForeignKey
(
Post
,
on_delete
=
models
.
CASCADE
,
null
=
True
,
related_name
=
"posts"
)
post
=
models
.
ForeignKey
(
Post
,
on_delete
=
models
.
CASCADE
,
null
=
True
,
related_name
=
"posts"
)
\ No newline at end of file
def
getReply
(
self
):
return
"Reply by {} {} {}:<br>{}<br>"
.
format
(
self
.
author
.
first_name
,
self
.
author
.
last_name
,
self
.
pub_date
,
self
.
reply_body
)
\ No newline at end of file
forum/views.py
View file @
eecd1b6e
from
django.shortcuts
import
render
from
django.shortcuts
import
render
from
django.http
import
HttpResponse
from
django.http
import
HttpResponse
from
.models
import
Post
,
Reply
def
index
(
request
):
def
index
(
request
):
return
HttpResponse
(
"Welcome to Widget's Forum!"
)
posts
=
Post
.
objects
.
all
()
formatted_posts
=
"FORUM POSTS:<br>"
for
post
in
posts
:
formatted_posts
+=
post
.
getPost
()
replies
=
Reply
.
objects
.
all
()
.
filter
(
post__post_title
=
post
)
for
reply
in
replies
:
formatted_posts
+=
reply
.
getReply
()
formatted_posts
+=
"<br>"
return
HttpResponse
(
formatted_posts
)
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