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
Hide 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
django.db
import
models
from
homepage.models
import
WidgetUser
from
homepage.models
import
WidgetUser
REACTION_CHOICES
=
[(
'Like'
,
'Like'
),
(
'Love'
,
'Love'
),
(
'Hate'
,
'Hate'
)]
class
Announcement
(
models
.
Model
):
class
Announcement
(
models
.
Model
):
author
=
models
.
ForeignKey
(
author
=
models
.
ForeignKey
(
...
@@ -22,6 +20,15 @@ class Reaction(models.Model):
...
@@ -22,6 +20,15 @@ class Reaction(models.Model):
Announcement
,
Announcement
,
on_delete
=
models
.
CASCADE
,
on_delete
=
models
.
CASCADE
,
)
)
LIKE
=
'Like'
LOVE
=
'Love'
ANGRY
=
'Angry'
REACTION_CHOICES
=
[
(
LIKE
,
'Like'
),
(
LOVE
,
'Love'
),
(
ANGRY
,
'Angry'
)
]
reaction_name
=
models
.
CharField
(
reaction_name
=
models
.
CharField
(
max_length
=
10
,
max_length
=
10
,
choices
=
REACTION_CHOICES
,
choices
=
REACTION_CHOICES
,
...
...
widget_Francoconuts/announcements/views.py
View file @
4c8d3031
...
@@ -7,13 +7,13 @@ def get_reactions(a):
...
@@ -7,13 +7,13 @@ def get_reactions(a):
reaction
=
''
reaction
=
''
like
=
Reaction
.
objects
.
filter
(
reaction_name
=
'Like'
,
announcement
=
a
)
like
=
Reaction
.
objects
.
filter
(
reaction_name
=
'Like'
,
announcement
=
a
)
love
=
Reaction
.
objects
.
filter
(
reaction_name
=
'Love'
,
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
:
for
l
in
like
:
reaction
+=
'{}: '
.
format
(
l
)
+
'{}'
.
format
(
l
.
tally
)
+
'<br>'
reaction
+=
'{}: '
.
format
(
l
)
+
'{}'
.
format
(
l
.
tally
)
+
'<br>'
for
l
in
love
:
for
l
in
love
:
reaction
+=
'{}: '
.
format
(
l
)
+
'{}'
.
format
(
l
.
tally
)
+
'<br>'
reaction
+=
'{}: '
.
format
(
l
)
+
'{}'
.
format
(
l
.
tally
)
+
'<br>'
for
h
in
hate
:
for
a
in
angry
:
reaction
+=
'{}: '
.
format
(
h
)
+
'{}'
.
format
(
h
.
tally
)
+
'<br>'
reaction
+=
'{}: '
.
format
(
a
)
+
'{}'
.
format
(
a
.
tally
)
+
'<br>'
return
reaction
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