Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
widget_Francoconuts
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Commits
Open sidebar
Chester Tan
widget_Francoconuts
Commits
02c09bf5
Commit
02c09bf5
authored
Apr 03, 2022
by
Mario Franco C. Deuna
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'Deuna/forum'
parents
e145e87d
9f5b222f
Changes
4
Show whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
81 additions
and
2 deletions
+81
-2
admin.py
widget_Francoconuts/forum/admin.py
+5
-1
0003_post_author_reply.py
...t_Francoconuts/forum/migrations/0003_post_author_reply.py
+30
-0
models.py
widget_Francoconuts/forum/models.py
+17
-0
views.py
widget_Francoconuts/forum/views.py
+29
-1
No files found.
widget_Francoconuts/forum/admin.py
View file @
02c09bf5
from
django.contrib
import
admin
from
django.contrib
import
admin
# Register your models here.
# Register your models here.
from
.models
import
Post
from
.models
import
Post
,
Reply
class
PostAdmin
(
admin
.
ModelAdmin
):
class
PostAdmin
(
admin
.
ModelAdmin
):
model
=
Post
model
=
Post
list_display
=
(
'post_title'
,
'pub_date'
)
list_display
=
(
'post_title'
,
'pub_date'
)
class
ReplyAdmin
(
admin
.
ModelAdmin
):
model
=
Reply
admin
.
site
.
register
(
Post
,
PostAdmin
)
admin
.
site
.
register
(
Post
,
PostAdmin
)
admin
.
site
.
register
(
Reply
,
ReplyAdmin
)
widget_Francoconuts/forum/migrations/0003_post_author_reply.py
0 → 100644
View file @
02c09bf5
# Generated by Django 4.0.3 on 2022-04-03 15:19
from
django.db
import
migrations
,
models
import
django.db.models.deletion
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'homepage'
,
'0001_initial'
),
(
'forum'
,
'0002_alter_post_pub_date'
),
]
operations
=
[
migrations
.
AddField
(
model_name
=
'post'
,
name
=
'author'
,
field
=
models
.
ForeignKey
(
default
=
0
,
on_delete
=
django
.
db
.
models
.
deletion
.
CASCADE
,
to
=
'homepage.widgetuser'
),
preserve_default
=
False
,
),
migrations
.
CreateModel
(
name
=
'Reply'
,
fields
=
[
(
'id'
,
models
.
BigAutoField
(
auto_created
=
True
,
primary_key
=
True
,
serialize
=
False
,
verbose_name
=
'ID'
)),
(
'reply_body'
,
models
.
CharField
(
max_length
=
500
)),
(
'pub_date'
,
models
.
DateField
(
auto_now_add
=
True
)),
(
'author'
,
models
.
ForeignKey
(
on_delete
=
django
.
db
.
models
.
deletion
.
CASCADE
,
to
=
'homepage.widgetuser'
)),
],
),
]
widget_Francoconuts/forum/models.py
View file @
02c09bf5
from
django.db
import
models
from
django.db
import
models
from
homepage.models
import
WidgetUser
# Create your models here.
# Create your models here.
class
Post
(
models
.
Model
):
class
Post
(
models
.
Model
):
post_title
=
models
.
CharField
(
max_length
=
30
)
post_title
=
models
.
CharField
(
max_length
=
30
)
post_body
=
models
.
TextField
(
max_length
=
500
)
post_body
=
models
.
TextField
(
max_length
=
500
)
pub_date
=
models
.
DateField
(
auto_now_add
=
True
)
pub_date
=
models
.
DateField
(
auto_now_add
=
True
)
author
=
models
.
ForeignKey
(
WidgetUser
,
on_delete
=
models
.
CASCADE
)
def
__str__
(
self
):
def
__str__
(
self
):
return
f
"{self.post_title} {self.post_body} {self.pub_date}"
return
f
"{self.post_title} {self.post_body} {self.pub_date}"
class
Reply
(
models
.
Model
):
reply_body
=
models
.
CharField
(
max_length
=
500
)
pub_date
=
models
.
DateField
(
auto_now_add
=
True
)
author
=
models
.
ForeignKey
(
WidgetUser
,
on_delete
=
models
.
CASCADE
)
def
__str__
(
self
):
return
f
"{self.reply_body} {self.pub_date}"
widget_Francoconuts/forum/views.py
View file @
02c09bf5
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
from
homepage.models
import
WidgetUser
def
get_reply
():
text
=
''
for
reply
in
Reply
.
objects
.
all
():
text
+=
(
'Reply by {} {} '
.
format
(
reply
.
author
.
first_name
,
reply
.
author
.
last_name
)
+
'dated {}'
)
.
format
(
reply
.
pub_date
.
strftime
(
'
%
x'
)
+
':<br>'
+
'{}<br>'
.
format
(
reply
.
reply_body
)
+
'<br>'
)
return
text
def
forum
(
request
):
def
forum
(
request
):
return
HttpResponse
(
"Welcome to Widget's Forum!"
)
text
=
'<h1>FORUM POSTS:</h1>'
for
post
in
Post
.
objects
.
all
():
text
+=
(
'{} '
.
format
(
post
.
post_title
)
+
'by {} {} '
.
format
(
post
.
author
.
first_name
,
post
.
author
.
last_name
)
+
'dated {}'
)
.
format
(
post
.
pub_date
.
strftime
(
'
%
x'
)
+
':<br>'
+
'{}<br>'
.
format
(
post
.
post_body
)
+
get_reply
()
)
return
HttpResponse
(
text
)
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