Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
widgets_FEKK
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
Kyla Martin
widgets_FEKK
Commits
9ee771ce
Commit
9ee771ce
authored
Mar 30, 2022
by
Kyla Martin
❓
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add Reactions Model, Author field in Announcement, and update view
parent
95715cd4
Changes
5
Show whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
81 additions
and
3 deletions
+81
-3
admin.py
WidgetFEKK/Announcements/admin.py
+13
-2
0002_announcement_author_reaction.py
...uncements/migrations/0002_announcement_author_reaction.py
+29
-0
models.py
WidgetFEKK/Announcements/models.py
+20
-0
views.py
WidgetFEKK/Announcements/views.py
+19
-1
db.sqlite3
WidgetFEKK/db.sqlite3
+0
-0
No files found.
WidgetFEKK/Announcements/admin.py
View file @
9ee771ce
...
...
@@ -2,6 +2,17 @@ from django.contrib import admin
# Register your models here.
from
.models
import
Announcement
from
.models
import
Announcement
,
Reaction
admin
.
site
.
register
(
Announcement
)
\ No newline at end of file
class
AnnouncementAdmin
(
admin
.
ModelAdmin
):
model
=
Announcement
search_fields
=
(
'announcement_title'
,
'announcement_body'
,
'author'
)
list_display
=
(
'announcement_title'
,)
list_filter
=
(
'author'
,
'announcement_title'
)
class
ReactionAdmin
(
admin
.
ModelAdmin
):
model
=
Reaction
list_display
=
(
'tally'
,)
admin
.
site
.
register
(
Announcement
,
AnnouncementAdmin
)
admin
.
site
.
register
(
Reaction
,
ReactionAdmin
)
\ No newline at end of file
WidgetFEKK/Announcements/migrations/0002_announcement_author_reaction.py
0 → 100644
View file @
9ee771ce
# Generated by Django 4.0.3 on 2022-03-27 04:16
from
django.db
import
migrations
,
models
import
django.db.models.deletion
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'Homepage'
,
'0001_initial'
),
(
'Announcements'
,
'0001_initial'
),
]
operations
=
[
migrations
.
AddField
(
model_name
=
'announcement'
,
name
=
'author'
,
field
=
models
.
ForeignKey
(
default
=
1
,
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'
),
(
'ANGRY'
,
'Angry'
)],
default
=
'LIKE'
,
max_length
=
5
)),
(
'tally'
,
models
.
IntegerField
()),
(
'announcement'
,
models
.
ForeignKey
(
on_delete
=
django
.
db
.
models
.
deletion
.
CASCADE
,
to
=
'Announcements.announcement'
)),
],
),
]
WidgetFEKK/Announcements/models.py
View file @
9ee771ce
from
django.db
import
models
from
Homepage.models
import
WidgetUser
class
Announcement
(
models
.
Model
):
announcement_title
=
models
.
CharField
(
max_length
=
100
)
announcement_body
=
models
.
CharField
(
max_length
=
500
)
pub_date
=
models
.
DateTimeField
(
"Date published"
,
auto_now_add
=
True
)
author
=
models
.
ForeignKey
(
WidgetUser
,
on_delete
=
models
.
CASCADE
,
default
=
1
)
def
__str__
(
self
):
return
self
.
announcement_title
class
Reaction
(
models
.
Model
):
like
=
'LIKE'
love
=
'LOVE'
angry
=
'ANGRY'
reaction_choices
=
[
(
like
,
'Like'
),
(
love
,
'Love'
),
(
angry
,
'Angry'
)
]
reaction_name
=
models
.
CharField
(
max_length
=
5
,
choices
=
reaction_choices
,
default
=
like
,)
tally
=
models
.
IntegerField
()
announcement
=
models
.
ForeignKey
(
Announcement
,
on_delete
=
models
.
CASCADE
)
def
__str__
(
self
):
return
self
.
reaction_name
\ No newline at end of file
WidgetFEKK/Announcements/views.py
View file @
9ee771ce
from
django.shortcuts
import
render
from
django.http
import
HttpResponse
from
.models
import
Announcement
,
Reaction
def
date_month_year
(
timestamp
):
return
timestamp
.
strftime
(
"
%
d/
%
m/
%
Y"
)
def
index
(
request
):
return
HttpResponse
(
"This is the Announcement Board!"
)
\ No newline at end of file
content
=
"ANNOUNCEMENTS:<br>"
announcements
=
Announcement
.
objects
.
all
()
for
announcements
in
announcements
:
content
+=
f
'{announcements.announcement_title} by {announcements.author.last_name}, {announcements.author.first_name} dated {date_month_year(announcements.pub_date)}: <br>'
content
+=
f
'{announcements.announcement_body} <br>'
reactions
=
announcements
.
reaction_set
.
all
()
for
reactions
in
reactions
:
content
+=
f
'{reactions.reaction_name}: {reactions.tally} <br>'
content
+=
'<br>'
return
HttpResponse
(
content
)
\ No newline at end of file
WidgetFEKK/db.sqlite3
View file @
9ee771ce
No preview for this file type
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