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
4c8d3031
Commit
4c8d3031
authored
May 14, 2022
by
Bryan Carlo Guanlao
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Changed reactions choices field
Moved the list to the reaction class and defined a constant for each value
parent
be7597e3
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
12 additions
and
5 deletions
+12
-5
models.py
widget_Francoconuts/announcements/models.py
+9
-2
views.py
widget_Francoconuts/announcements/views.py
+3
-3
No files found.
widget_Francoconuts/announcements/models.py
View file @
4c8d3031
from
django.db
import
models
from
homepage.models
import
WidgetUser
REACTION_CHOICES
=
[(
'Like'
,
'Like'
),
(
'Love'
,
'Love'
),
(
'Hate'
,
'Hate'
)]
class
Announcement
(
models
.
Model
):
author
=
models
.
ForeignKey
(
...
...
@@ -22,6 +20,15 @@ class Reaction(models.Model):
Announcement
,
on_delete
=
models
.
CASCADE
,
)
LIKE
=
'Like'
LOVE
=
'Love'
ANGRY
=
'Angry'
REACTION_CHOICES
=
[
(
LIKE
,
'Like'
),
(
LOVE
,
'Love'
),
(
ANGRY
,
'Angry'
)
]
reaction_name
=
models
.
CharField
(
max_length
=
10
,
choices
=
REACTION_CHOICES
,
...
...
widget_Francoconuts/announcements/views.py
View file @
4c8d3031
...
...
@@ -7,13 +7,13 @@ def get_reactions(a):
reaction
=
''
like
=
Reaction
.
objects
.
filter
(
reaction_name
=
'Like'
,
announcement
=
a
)
love
=
Reaction
.
objects
.
filter
(
reaction_name
=
'Love'
,
announcement
=
a
)
hate
=
Reaction
.
objects
.
filter
(
reaction_name
=
'Hate
'
,
announcement
=
a
)
angry
=
Reaction
.
objects
.
filter
(
reaction_name
=
'Angry
'
,
announcement
=
a
)
for
l
in
like
:
reaction
+=
'{}: '
.
format
(
l
)
+
'{}'
.
format
(
l
.
tally
)
+
'<br>'
for
l
in
love
:
reaction
+=
'{}: '
.
format
(
l
)
+
'{}'
.
format
(
l
.
tally
)
+
'<br>'
for
h
in
hate
:
reaction
+=
'{}: '
.
format
(
h
)
+
'{}'
.
format
(
h
.
tally
)
+
'<br>'
for
a
in
angry
:
reaction
+=
'{}: '
.
format
(
a
)
+
'{}'
.
format
(
a
.
tally
)
+
'<br>'
return
reaction
...
...
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