Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
midterm_vincentdjango
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
1
Merge Requests
1
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
Almira Redoble
midterm_vincentdjango
Commits
88a544bc
Commit
88a544bc
authored
May 07, 2023
by
Joaquin Inigo Crisologo
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Created forum.html and ForumPostDetailView
parent
7d762344
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
56 additions
and
32 deletions
+56
-32
models.py
widget_vincentdjango/forum/models.py
+6
-0
forum.html
widget_vincentdjango/forum/templates/forum/forum.html
+17
-0
forumpost-details.html
...incentdjango/forum/templates/forum/forumpost-details.html
+20
-0
urls.py
widget_vincentdjango/forum/urls.py
+2
-1
views.py
widget_vincentdjango/forum/views.py
+11
-31
No files found.
widget_vincentdjango/forum/models.py
View file @
88a544bc
# forum/models.py
# forum/models.py
from
django.db
import
models
from
django.db
import
models
from
dashboard.models
import
WidgetUser
from
dashboard.models
import
WidgetUser
from
django.urls
import
reverse
class
ForumPost
(
models
.
Model
):
class
ForumPost
(
models
.
Model
):
title
=
models
.
CharField
(
max_length
=
100
)
title
=
models
.
CharField
(
max_length
=
100
)
...
@@ -19,12 +20,17 @@ class ForumPost(models.Model):
...
@@ -19,12 +20,17 @@ class ForumPost(models.Model):
def
format_pub_datetime
(
self
):
def
format_pub_datetime
(
self
):
return
self
.
pub_datetime
.
strftime
(
'
%
m/
%
d/
%
Y
%
I:
%
M
%
p'
)
return
self
.
pub_datetime
.
strftime
(
'
%
m/
%
d/
%
Y
%
I:
%
M
%
p'
)
def
get_absolute_url
(
self
):
return
reverse
(
'forum:forumpost-details'
,
kwargs
=
{
'pk'
:
self
.
pk
})
class
Reply
(
models
.
Model
):
class
Reply
(
models
.
Model
):
post
=
models
.
ForeignKey
(
post
=
models
.
ForeignKey
(
ForumPost
,
ForumPost
,
null
=
True
,
null
=
True
,
default
=
True
,
default
=
True
,
on_delete
=
models
.
CASCADE
,
on_delete
=
models
.
CASCADE
,
related_name
=
"replies"
,
)
)
body
=
models
.
CharField
(
max_length
=
200
)
body
=
models
.
CharField
(
max_length
=
200
)
author
=
models
.
ForeignKey
(
author
=
models
.
ForeignKey
(
...
...
widget_vincentdjango/forum/templates/forum/forum.html
0 → 100644
View file @
88a544bc
{% extends 'base.html' %}
{% load static %}
{% block title %} Widget's Forum {% endblock %}
{% block heading %}
<h1>
Welcome to Widget's Forum!
</h1>
{% endblock %}
{% block content %}
<h2>
Forum Posts:
</h2>
<ul>
{% for forumpost in forumposts %}
<li>
<a
href=
"{{ forumpost.get_absolute_url }}"
>
{{ forumpost.title }} by {{ forumpost.author.first_name }} {{ forumpost.author.last_name }}
</a>
</li>
{% endfor %}
</ul>
{% endblock %}
\ No newline at end of file
widget_vincentdjango/forum/templates/forum/forumpost-details.html
0 → 100644
View file @
88a544bc
{% extends 'base.html' %}
{% load static %}
{% block title %} {{ object.title }} {% endblock %}
{% block heading %}
<h1>
{{ object.title }}
</h1>
<h2>
by {{ object.author.first_name }} {{ object.author.last_name }}
</h2>
<h4>
{{ object.format_pub_datetime }}
</h4>
<p>
{{ object.body }}
</p>
{% endblock %}
{% block content %}
<hr>
<h2>
Post Replies:
</h2>
{% for reply in object.replies.all %}
<p>
by {{ reply.author.first_name }} {{ reply.author.last_name }}
</p>
<p>
{{ reply.format_pub_datetime }}
</p>
<p>
{{ reply.body }}
</p>
<br>
{% endfor %}
{% endblock %}
\ No newline at end of file
widget_vincentdjango/forum/urls.py
View file @
88a544bc
# forum/urls.py
# forum/urls.py
from
django.urls
import
path
from
django.urls
import
path
from
.views
import
index
from
.views
import
index
,
ForumPostDetailView
urlpatterns
=
[
urlpatterns
=
[
path
(
''
,
index
,
name
=
'index'
),
path
(
''
,
index
,
name
=
'index'
),
path
(
'forumposts/<int:pk>/details'
,
ForumPostDetailView
.
as_view
(),
name
=
'forumpost-details'
),
]
]
# This might be needed, depending on your Django version
# This might be needed, depending on your Django version
...
...
widget_vincentdjango/forum/views.py
View file @
88a544bc
# appname/views.py
from
django.shortcuts
import
render
from
django.shortcuts
import
render
from
django.http
import
HttpResponse
from
django.http
import
HttpResponse
from
.models
import
ForumPost
,
Reply
from
django.views.generic.detail
import
DetailView
from
dashboard.models
import
WidgetUser
from
django.views.generic.edit
import
CreateView
,
UpdateView
def
index
(
request
):
head
=
"<h1 style='border-bottom:4px solid lightgray;
\
from
dashboard.models
import
WidgetUser
padding-bottom:30px;
\
from
.models
import
ForumPost
,
Reply
font-size:450
%
;'>
\
Widget Forum
\
</h1>"
body
=
"<h2>Forum Posts:</h2>"
for
post
in
ForumPost
.
objects
.
all
():
body
+=
"<div style='border: 2px solid gray; border-radius:5px; padding:20px 30px;'>
\
<b>{}</b> by {} {} posted {}:
\
<br>
\
{}"
.
format
(
post
.
title
,
post
.
author
.
first_name
,
post
.
author
.
last_name
,
post
.
format_pub_datetime
(),
post
.
body
)
for
reply
in
Reply
.
objects
.
all
():
if
reply
.
post
==
post
:
body
+=
"<p style='border: 1px dashed gray; border-radius:5px; padding:20px 30px;'>
\
Reply by {} {} posted {}:
\
<br>
\
{}"
.
format
(
reply
.
author
.
first_name
,
reply
.
author
.
last_name
,
reply
.
format_pub_datetime
(),
reply
.
body
)
body
+=
"</div>"
body
+=
"<p> </p>"
return_string
=
"<html>
\
def
index
(
request
):
<body style = 'font-family:helvetica;
\
forumposts
=
ForumPost
.
objects
.
all
()
padding:30px;'>
\
replies
=
Reply
.
objects
.
all
()
{}{}
\
return
render
(
request
,
'forum/forum.html'
,
{
'forumposts'
:
forumposts
,
'replies'
:
replies
})
</body></html>"
.
format
(
head
,
body
)
return
HttpResponse
(
return_string
)
class
ForumPostDetailView
(
DetailView
):
model
=
ForumPost
template_name
=
'forum/forumpost-details.html'
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