Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
W
widget_father when can i be on my own i have the hello world to see
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
father when can i be on my own i have the hello world to see
widget_father when can i be on my own i have the hello world to see
Commits
80ce3337
Commit
80ce3337
authored
Apr 03, 2022
by
Emilio Gentolia
Browse files
Options
Browse Files
Download
Plain Diff
Merge branch 'gentolia/announcement_board'
parents
483b128b
7a593964
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
106 additions
and
3 deletions
+106
-3
admin.py
announcement_board/admin.py
+5
-1
0002_announcement_author_alter_announcement_pub_date_and_more.py
...nouncement_author_alter_announcement_pub_date_and_more.py
+34
-0
0003_alter_announcement_pub_date.py
...ment_board/migrations/0003_alter_announcement_pub_date.py
+18
-0
models.py
announcement_board/models.py
+26
-1
views.py
announcement_board/views.py
+23
-1
No files found.
announcement_board/admin.py
View file @
80ce3337
from
django.contrib
import
admin
from
.models
import
Announcement
from
.models
import
Announcement
,
Reaction
#Announcement admin panel
class
AnnouncementAdmin
(
admin
.
ModelAdmin
):
model
=
Announcement
class
ReactionAdmin
(
admin
.
ModelAdmin
):
model
=
Reaction
admin
.
site
.
register
(
Announcement
,
AnnouncementAdmin
)
admin
.
site
.
register
(
Reaction
,
AnnouncementAdmin
)
\ No newline at end of file
announcement_board/migrations/0002_announcement_author_alter_announcement_pub_date_and_more.py
0 → 100644
View file @
80ce3337
# Generated by Django 4.0.3 on 2022-04-02 16:00
from
django.db
import
migrations
,
models
import
django.db.models.deletion
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'homepage'
,
'0001_initial'
),
(
'announcement_board'
,
'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
.
AlterField
(
model_name
=
'announcement'
,
name
=
'pub_date'
,
field
=
models
.
DateTimeField
(
verbose_name
=
'date published'
),
),
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
(
default
=
0
)),
(
'announcement'
,
models
.
ForeignKey
(
on_delete
=
django
.
db
.
models
.
deletion
.
CASCADE
,
to
=
'announcement_board.announcement'
)),
],
),
]
announcement_board/migrations/0003_alter_announcement_pub_date.py
0 → 100644
View file @
80ce3337
# Generated by Django 4.0.3 on 2022-04-03 08:00
from
django.db
import
migrations
,
models
class
Migration
(
migrations
.
Migration
):
dependencies
=
[
(
'announcement_board'
,
'0002_announcement_author_alter_announcement_pub_date_and_more'
),
]
operations
=
[
migrations
.
AlterField
(
model_name
=
'announcement'
,
name
=
'pub_date'
,
field
=
models
.
DateField
(
verbose_name
=
'date published'
),
),
]
announcement_board/models.py
View file @
80ce3337
from
django.db
import
models
from
homepage.models
import
WidgetUser
class
Announcement
(
models
.
Model
):
announcement_title
=
models
.
CharField
(
max_length
=
120
)
announcement_body
=
models
.
TextField
(
blank
=
True
)
pub_date
=
models
.
DateField
(
auto_now_add
=
True
)
pub_date
=
models
.
DateField
(
"date published"
)
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
(
default
=
0
)
announcement
=
models
.
ForeignKey
(
Announcement
,
on_delete
=
models
.
CASCADE
)
def
__str__
(
self
):
return
self
.
reaction_name
\ No newline at end of file
announcement_board/views.py
View file @
80ce3337
from
django.http
import
HttpResponse
from
.models
import
Announcement
,
Reaction
# View for announcements page.
def
index
(
request
):
return
HttpResponse
(
"This is the Announcement Board!"
)
return
HttpResponse
(
display_announcementboard
(
Announcement
.
objects
.
all
(),
Reaction
.
objects
.
all
()))
def
display_announcementboard
(
announcement_data
,
reaction_data
):
display_output
=
"ANNOUNCEMENTS: <br>"
for
object
in
announcement_data
:
announcement_title
=
object
.
announcement_title
first_name
=
object
.
author
.
first_name
last_name
=
object
.
author
.
last_name
pub_date
=
str
(
object
.
pub_date
)
announcement_body
=
object
.
announcement_body
like_count
=
Reaction
.
objects
.
filter
(
announcement_id
=
object
.
id
)
.
filter
(
reaction_name
=
"Like"
)
.
first
()
.
tally
love_count
=
Reaction
.
objects
.
filter
(
announcement_id
=
object
.
id
)
.
filter
(
reaction_name
=
"Love"
)
.
first
()
.
tally
angry_count
=
Reaction
.
objects
.
filter
(
announcement_id
=
object
.
id
)
.
filter
(
reaction_name
=
"Angry"
)
.
first
()
.
tally
display_output
+=
f
'''
{announcement_title} by {first_name} {last_name} dated {pub_date}:<br>
{announcement_body}<br>
Like: {like_count}<br>
Love: {love_count}<br>
Angry: {angry_count}<br>
<br>
'''
return
display_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