Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
midterm_gitgud
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
Neal Luigi D. Rodriguez
midterm_gitgud
Commits
ae66f7b7
Commit
ae66f7b7
authored
May 12, 2023
by
Eury See
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Created the Per Forum Post Details Page for the Forum application.
parent
3c88e239
Changes
8
Show whitespace changes
Inline
Side-by-side
Showing
8 changed files
with
100 additions
and
14 deletions
+100
-14
0004_forumpost_replies.py
widget_gitgud/Forum/migrations/0004_forumpost_replies.py
+18
-0
models.py
widget_gitgud/Forum/models.py
+4
-1
forum.html
widget_gitgud/Forum/templates/forum.html
+1
-1
forumpost-details.html
widget_gitgud/Forum/templates/forumpost-details.html
+40
-0
urls.py
widget_gitgud/Forum/urls.py
+3
-1
views.py
widget_gitgud/Forum/views.py
+16
-11
db.sqlite3
widget_gitgud/db.sqlite3
+0
-0
0006_alter_event_activity.py
...ud/widgetcalendar/migrations/0006_alter_event_activity.py
+18
-0
No files found.
widget_gitgud/Forum/migrations/0004_forumpost_replies.py
0 → 100644
View file @
ae66f7b7
# Generated by Django 4.1.7 on 2023-05-11 10:32
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'Forum'
,
'0003_alter_forumpost_author_alter_reply_author'
),
]
operations
=
[
migrations
.
AddField
(
model_name
=
'forumpost'
,
name
=
'replies'
,
field
=
models
.
ManyToManyField
(
blank
=
True
,
to
=
'Forum.forumpost'
),
),
]
widget_gitgud/Forum/models.py
View file @
ae66f7b7
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
)
...
@@ -10,9 +11,11 @@ class ForumPost(models.Model):
...
@@ -10,9 +11,11 @@ class ForumPost(models.Model):
def
__str__
(
self
):
def
__str__
(
self
):
return
self
.
title
return
self
.
title
replies
=
models
.
ManyToManyField
(
'self'
,
blank
=
True
)
class
Reply
(
models
.
Model
):
class
Reply
(
models
.
Model
):
body
=
models
.
TextField
()
body
=
models
.
TextField
()
author
=
models
.
ForeignKey
(
WidgetUser
,
on_delete
=
models
.
PROTECT
)
author
=
models
.
ForeignKey
(
WidgetUser
,
on_delete
=
models
.
PROTECT
,
related_name
=
'replies'
)
pub_datetime
=
models
.
DateTimeField
()
pub_datetime
=
models
.
DateTimeField
()
forum_post
=
models
.
ForeignKey
(
ForumPost
,
on_delete
=
models
.
CASCADE
)
forum_post
=
models
.
ForeignKey
(
ForumPost
,
on_delete
=
models
.
CASCADE
)
...
...
widget_gitgud/Forum/templates/forum.html
View file @
ae66f7b7
...
@@ -20,7 +20,7 @@
...
@@ -20,7 +20,7 @@
<p1>
Forum posts:
</p1>
<p1>
Forum posts:
</p1>
{% for post in posts %}
{% for post in posts %}
<li>
{{post.title}} by {{post.author}}
</a></li>
<li>
<a
href=
"{% url 'Forum:forumpost-details' pk=post.pk %}"
>
{{post.title}} by {{post.author}}
</a></li>
{% endfor %}
{% endfor %}
<br>
<br>
...
...
widget_gitgud/Forum/templates/forumpost-details.html
0 → 100644
View file @
ae66f7b7
<title>
{% block title %} {{object.title}} {% endblock %}
</title>
{% block styles %}
<style>
body
{
background-color
:
rgb
(
202
,
255
,
206
);
font-family
:
Georgia
,
serif
;
font-size
:
16px
;
color
:
rgb
(
90
,
154
,
78
);
}
</style>
{% endblock %}
{% block content %}
<div
class=
"center"
>
<h1>
{{ object.title }}
</h1>
by {{ object.author }}
<br>
{{ object.pub_datetime }}
<br>
{{ object.body }}
<p>
Post Replies:
</p>
{% for reply in replies %}
by {{ reply.author }}
{{ reply.pub_datetime }}
{{ reply.body }}
{% empty %}
No replies yet.
{% endfor %}
<form
method=
"post"
>
{% csrf_token %}
<br><button
type=
"submit"
>
Edit Post
</button>
</form>
</div>
{% endblock %}
\ No newline at end of file
widget_gitgud/Forum/urls.py
View file @
ae66f7b7
from
django.urls
import
path
from
django.urls
import
path
from
.views
import
index
,
forum
from
.views
import
(
index
,
forum
,
ForumDetailView
)
from
.
import
views
from
.
import
views
urlpatterns
=
[
urlpatterns
=
[
path
(
""
,
views
.
index
,
name
=
"index"
),
path
(
""
,
views
.
index
,
name
=
"index"
),
path
(
'forum/'
,
forum
,
name
=
'forum'
),
path
(
'forum/'
,
forum
,
name
=
'forum'
),
path
(
'forum/forumposts/<int:pk>/details/'
,
ForumDetailView
.
as_view
(),
name
=
'forumpost-details'
),
]
]
app_name
=
"Forum"
app_name
=
"Forum"
\ No newline at end of file
widget_gitgud/Forum/views.py
View file @
ae66f7b7
from
django.shortcuts
import
render
from
django.shortcuts
import
render
from
django.http
import
HttpResponse
from
django.http
import
HttpResponse
from
django.views
import
View
from
django.views
import
View
from
django.views.generic.detail
import
DetailView
from
.models
import
ForumPost
,
Reply
from
.models
import
ForumPost
,
Reply
def
forum
(
request
):
# Query the database to get the forum posts
posts
=
ForumPost
.
objects
.
all
()
# Pass the posts to the template
context
=
{
'posts'
:
posts
}
# Render the template
return
render
(
request
,
'forum.html'
,
context
)
def
index
(
request
):
def
index
(
request
):
return_string
=
"<br>"
return_string
=
"<br>"
for
reply
in
Reply
.
objects
.
all
():
for
reply
in
Reply
.
objects
.
all
():
...
@@ -25,3 +16,17 @@ def index(request):
...
@@ -25,3 +16,17 @@ def index(request):
html_string
=
"<html><head> Widget's Forum <br><br> Forum Posts: </head><body> {} </body><html>"
.
format
(
return_string
)
html_string
=
"<html><head> Widget's Forum <br><br> Forum Posts: </head><body> {} </body><html>"
.
format
(
return_string
)
return
HttpResponse
(
html_string
)
return
HttpResponse
(
html_string
)
def
forum
(
request
):
posts
=
ForumPost
.
objects
.
all
()
context
=
{
'posts'
:
posts
}
return
render
(
request
,
'forum.html'
,
context
)
class
ForumDetailView
(
DetailView
):
model
=
ForumPost
template_name
=
'forumpost-details.html'
def
get_context_data
(
self
,
**
kwargs
):
context
=
super
()
.
get_context_data
(
**
kwargs
)
context
[
'replies'
]
=
self
.
object
.
replies
.
all
()
return
context
widget_gitgud/db.sqlite3
View file @
ae66f7b7
No preview for this file type
widget_gitgud/widgetcalendar/migrations/0006_alter_event_activity.py
0 → 100644
View file @
ae66f7b7
# Generated by Django 4.1.7 on 2023-05-11 10:32
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'widgetcalendar'
,
'0005_alter_event_course_alter_event_location'
),
]
operations
=
[
migrations
.
AlterField
(
model_name
=
'event'
,
name
=
'activity'
,
field
=
models
.
TextField
(
default
=
''
,
max_length
=
1000
),
),
]
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