Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
M
midterm_casanatics
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
John Aidan Vincent M. Ng
midterm_casanatics
Commits
90a98469
Commit
90a98469
authored
Mar 04, 2023
by
Javi Ng
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
created admin panel for Announcement Board
parent
36825a81
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
49 additions
and
0 deletions
+49
-0
admin.py
widget_casanatics/announcement_board/admin.py
+49
-0
No files found.
widget_casanatics/announcement_board/admin.py
View file @
90a98469
from
django.contrib
import
admin
from
django.contrib
import
admin
from
.models
import
Announcement
,
Reaction
# Register your models here.
# Register your models here.
# show reactions in page for announcements
class
ReactionInline
(
admin
.
TabularInline
):
model
=
Reaction
# announcement admin panel
class
AnnouncementAdmin
(
admin
.
ModelAdmin
):
model
=
Announcement
# display title, body, datetime, author
list_display
=
(
"title"
,
"get_author"
,
"pub_datetime"
,
"body"
)
# search by title or body
search_fields
=
(
"title"
,
"body"
)
# filter by author
list_filter
=
(
"get_author"
)
def
get_author
(
self
,
obj
):
return
obj
.
author
.
displayName
()
get_author
.
short_description
=
"Author Name"
get_author
.
admin_order_field
=
"author"
inlines
=
[
ReactionInline
]
class
ReactionAdmin
(
admin
.
ModelAdmin
):
# display reaction name, tally, announcement
list_display
=
(
"reaction_name"
,
"tally"
,
"get_name"
)
# search by announcement name
search_fields
=
(
"get_name"
)
# filter by announcement
list_filter
=
(
"get_name"
)
def
get_name
(
self
,
obj
):
return
obj
.
announcement
.
title
# title of column for get_name
get_name
.
short_description
=
"Announcement Title"
# sorting by announcement
get_name
.
admin_order_field
=
"announcement"
admin
.
site
.
register
(
Announcement
,
AnnouncementAdmin
)
admin
.
site
.
register
(
Reaction
,
ReactionAdmin
)
\ No newline at end of file
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