Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SRCT
roomlist
Commits
713e7680
Commit
713e7680
authored
Dec 05, 2015
by
Daniel W Bond
Browse files
customized admin interface for Students and Majors
parent
c571fe57
Changes
1
Hide whitespace changes
Inline
Side-by-side
roomlist/accounts/admin.py
View file @
713e7680
...
...
@@ -5,6 +5,24 @@ from django.contrib import admin
# imports from your apps
from
.models
import
Student
,
Major
,
Confirmation
admin
.
site
.
register
(
Major
)
admin
.
site
.
register
(
Student
)
class
StudentAdmin
(
admin
.
ModelAdmin
):
list_display
=
(
"get_name"
,
"room"
,
"privacy"
,
"major"
,
"created"
)
def
get_name
(
self
,
student
):
return
student
.
get_full_name_or_uname
()
get_name
.
short_description
=
'Name'
get_name
.
admin_order_field
=
'user__username'
# ordering by callables is hard
class
MajorAdmin
(
admin
.
ModelAdmin
):
list_display
=
(
"name"
,
"get_major_num"
,
)
def
get_major_num
(
self
,
major
):
student_num
=
Student
.
objects
.
filter
(
major
=
major
).
count
()
return
student_num
get_major_num
.
short_description
=
'Number of Students'
# ordering is hard (ditto above; rewrite queryset :-/)
admin
.
site
.
register
(
Student
,
StudentAdmin
)
admin
.
site
.
register
(
Major
,
MajorAdmin
)
admin
.
site
.
register
(
Confirmation
)
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