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
cf8d3ce5
Commit
cf8d3ce5
authored
Apr 03, 2022
by
Bryan Carlo Guanlao
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'guanlao/announcements'
parents
fc7602a2
0108d3cb
Changes
7
Hide whitespace changes
Inline
Side-by-side
Showing
7 changed files
with
93 additions
and
5 deletions
+93
-5
admin.py
widget_Francoconuts/announcements/admin.py
+7
-1
0001_initial.py
widget_Francoconuts/announcements/migrations/0001_initial.py
+13
-1
0002_rename_announcement_name_reaction_announcement.py
...ns/0002_rename_announcement_name_reaction_announcement.py
+18
-0
models.py
widget_Francoconuts/announcements/models.py
+23
-0
views.py
widget_Francoconuts/announcements/views.py
+31
-2
0001_initial.py
widget_Francoconuts/homepage/migrations/0001_initial.py
+1
-1
__init__.py
widget_Francoconuts/homepage/migrations/__init__.py
+0
-0
No files found.
widget_Francoconuts/announcements/admin.py
View file @
cf8d3ce5
from
django.contrib
import
admin
from
.models
import
Announcement
from
.models
import
Announcement
,
Reaction
class
AnnouncementAdmin
(
admin
.
ModelAdmin
):
...
...
@@ -8,4 +8,10 @@ class AnnouncementAdmin(admin.ModelAdmin):
list_display
=
(
'announcement_title'
,
'pub_date'
)
class
ReactionAdmin
(
admin
.
ModelAdmin
):
model
=
Reaction
list_display
=
(
'reaction_name'
,
'announcement'
,
'tally'
)
admin
.
site
.
register
(
Announcement
,
AnnouncementAdmin
)
admin
.
site
.
register
(
Reaction
,
ReactionAdmin
)
widget_Francoconuts/announcements/migrations/0001_initial.py
View file @
cf8d3ce5
# Generated by Django 3.2.12 on 2022-0
3-22 18:58
# Generated by Django 3.2.12 on 2022-0
4-03 02:52
from
django.db
import
migrations
,
models
import
django.db.models.deletion
class
Migration
(
migrations
.
Migration
):
...
...
@@ -8,6 +9,7 @@ class Migration(migrations.Migration):
initial
=
True
dependencies
=
[
(
'homepage'
,
'0001_initial'
),
]
operations
=
[
...
...
@@ -18,6 +20,16 @@ class Migration(migrations.Migration):
(
'announcement_title'
,
models
.
CharField
(
max_length
=
50
)),
(
'announcement_body'
,
models
.
TextField
(
max_length
=
500
)),
(
'pub_date'
,
models
.
DateField
(
auto_now_add
=
True
)),
(
'author'
,
models
.
ForeignKey
(
on_delete
=
django
.
db
.
models
.
deletion
.
CASCADE
,
to
=
'homepage.widgetuser'
)),
],
),
migrations
.
CreateModel
(
name
=
'Reaction'
,
fields
=
[
(
'id'
,
models
.
BigAutoField
(
auto_created
=
True
,
primary_key
=
True
,
serialize
=
False
,
verbose_name
=
'ID'
)),
(
'reaction_name'
,
models
.
CharField
(
choices
=
[(
'Like'
,
'Like'
),
(
'Love'
,
'Love'
),
(
'Hate'
,
'Hate'
)],
default
=
'Like'
,
max_length
=
10
)),
(
'tally'
,
models
.
IntegerField
()),
(
'announcement_name'
,
models
.
ForeignKey
(
on_delete
=
django
.
db
.
models
.
deletion
.
CASCADE
,
to
=
'announcements.announcement'
)),
],
),
]
widget_Francoconuts/announcements/migrations/0002_rename_announcement_name_reaction_announcement.py
0 → 100644
View file @
cf8d3ce5
# Generated by Django 3.2.12 on 2022-04-03 02:55
from
django.db
import
migrations
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'announcements'
,
'0001_initial'
),
]
operations
=
[
migrations
.
RenameField
(
model_name
=
'reaction'
,
old_name
=
'announcement_name'
,
new_name
=
'announcement'
,
),
]
widget_Francoconuts/announcements/models.py
View file @
cf8d3ce5
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
(
WidgetUser
,
on_delete
=
models
.
CASCADE
,
)
announcement_title
=
models
.
CharField
(
max_length
=
50
)
announcement_body
=
models
.
TextField
(
max_length
=
500
)
pub_date
=
models
.
DateField
(
auto_now_add
=
True
)
def
__str__
(
self
):
return
'{}'
.
format
(
self
.
announcement_title
)
class
Reaction
(
models
.
Model
):
announcement
=
models
.
ForeignKey
(
Announcement
,
on_delete
=
models
.
CASCADE
,
)
reaction_name
=
models
.
CharField
(
max_length
=
10
,
choices
=
REACTION_CHOICES
,
default
=
'Like'
)
tally
=
models
.
IntegerField
()
def
__str__
(
self
):
return
'{}'
.
format
(
self
.
reaction_name
)
widget_Francoconuts/announcements/views.py
View file @
cf8d3ce5
from
django.shortcuts
import
render
from
django.http
import
HttpResponse
from
django.http
import
Http404
,
HttpRequest
,
HttpResponse
from
.models
import
Announcement
,
Reaction
,
WidgetUser
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
)
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>'
return
reaction
def
announcements
(
request
):
return
HttpResponse
(
"This is the Announcement Board!"
)
text
=
'ANNOUNCEMENTS:<br>'
for
announcement
in
Announcement
.
objects
.
all
():
text
+=
(
'{} '
.
format
(
announcement
)
+
'by {} {} '
.
format
(
announcement
.
author
.
first_name
,
announcement
.
author
.
last_name
)
+
'dated {}'
)
.
format
(
announcement
.
pub_date
.
strftime
(
'
%
x'
)
+
':<br>'
+
'{}<br>'
.
format
(
announcement
.
announcement_body
)
+
get_reactions
(
announcement
)
+
'<br>'
)
return
HttpResponse
(
text
)
widget_Francoconuts/homepage/migrations/0001_initial.py
View file @
cf8d3ce5
# Generated by Django
4.0.3 on 2022-03-22 03:09
# Generated by Django
3.2.12 on 2022-04-03 02:44
from
django.db
import
migrations
,
models
...
...
widget_Francoconuts/homepage/migrations/__init__.py
0 → 100644
View file @
cf8d3ce5
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