Skip to content
GitLab
Projects
Groups
Snippets
Help
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
R
roomlist
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
23
Issues
23
List
Boards
Labels
Service Desk
Milestones
Merge Requests
2
Merge Requests
2
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Operations
Operations
Incidents
Environments
Analytics
Analytics
CI / CD
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
SRCT
roomlist
Commits
713e7680
Commit
713e7680
authored
Dec 05, 2015
by
Daniel W Bond
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
customized admin interface for Students and Majors
parent
c571fe57
Changes
1
Hide whitespace changes
Inline
Side-by-side
Showing
1 changed file
with
20 additions
and
2 deletions
+20
-2
roomlist/accounts/admin.py
roomlist/accounts/admin.py
+20
-2
No files found.
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