Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
widget_group22
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
John Tamano
widget_group22
Commits
7f30c066
Commit
7f30c066
authored
Apr 06, 2022
by
Julliana Zarah C. Cruz
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Updated views.py and models.py to display announcements
parent
2f50125c
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
37 additions
and
4 deletions
+37
-4
models.py
widget_group22/announcements/models.py
+8
-3
views.py
widget_group22/announcements/views.py
+29
-1
No files found.
widget_group22/announcements/models.py
View file @
7f30c066
...
@@ -18,7 +18,10 @@ class Reaction(models.Model):
...
@@ -18,7 +18,10 @@ class Reaction(models.Model):
max_length
=
5
,
max_length
=
5
,
choices
=
REACTION_CHOICES
,
choices
=
REACTION_CHOICES
,
)
)
tally
=
models
.
AutoField
(
primary_key
=
True
)
tally
=
1
def
__str__
(
self
):
return
'{}'
.
format
(
self
.
reaction_name
)
class
Announcement
(
models
.
Model
):
class
Announcement
(
models
.
Model
):
...
@@ -28,5 +31,7 @@ class Announcement(models.Model):
...
@@ -28,5 +31,7 @@ class Announcement(models.Model):
author
=
models
.
ForeignKey
(
author
=
models
.
ForeignKey
(
'homepage.WidgetUser'
,
'homepage.WidgetUser'
,
on_delete
=
models
.
CASCADE
,
on_delete
=
models
.
CASCADE
,
#related_name='author'
)
)
\ No newline at end of file
def
__str__
(
self
):
return
'{}'
.
format
(
self
.
announcement_title
)
\ No newline at end of file
widget_group22/announcements/views.py
View file @
7f30c066
from
django.shortcuts
import
render
from
django.shortcuts
import
render
from
django.http
import
HttpResponse
from
django.http
import
HttpResponse
from
.
import
models
from
.models
import
Announcement
,
Reaction
def
announcements
(
request
):
def
index
(
request
):
return
HttpResponse
(
'This is the Announcement Board!'
)
return
HttpResponse
(
'This is the Announcement Board!'
)
def
announcements
(
request
):
all_announcements
=
models
.
Announcement
.
objects
.
all
()
#all_reactions = models.Reaction.objects.all()
final_output
=
''
for
i
in
all_announcements
:
title
=
i
.
announcement_title
body
=
i
.
announcement_body
date
=
i
.
pub_date
last_name
=
i
.
author
.
last_name
first_name
=
i
.
author
.
first_name
like_tally
=
Reaction
.
objects
.
filter
(
reaction_name
=
'Like'
,
announcement
=
i
)
.
count
()
love_tally
=
Reaction
.
objects
.
filter
(
reaction_name
=
'Love'
,
announcement
=
i
)
.
count
()
angry_tally
=
Reaction
.
objects
.
filter
(
reaction_name
=
'Angry'
,
announcement
=
i
)
.
count
()
output
=
(
title
+
' by '
+
first_name
+
' '
+
last_name
+
' dated '
+
date
+
':<br>'
+
body
+
'<br>'
+
'Like: '
+
like_tally
+
'<br>'
+
'Love: '
+
love_tally
+
'<br>'
+
'Angry: '
+
angry_tally
)
final_output
+=
output
+
'<br><br>'
return
HttpResponse
(
'<h1>ANNOUNCEMENTS: </h1>'
+
final_output
)
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