Commit 713e7680 authored by Daniel W Bond's avatar Daniel W Bond

customized admin interface for Students and Majors

parent c571fe57
...@@ -5,6 +5,24 @@ from django.contrib import admin ...@@ -5,6 +5,24 @@ from django.contrib import admin
# imports from your apps # imports from your apps
from .models import Student, Major, Confirmation from .models import Student, Major, Confirmation
admin.site.register(Major) class StudentAdmin(admin.ModelAdmin):
admin.site.register(Student) 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) admin.site.register(Confirmation)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment