ernestophone.ens.fr/gestion/admin.py

36 lines
1.3 KiB
Python
Raw Normal View History

2015-03-17 19:03:51 +01:00
from django.contrib import admin
from django.contrib.auth.models import User, Group
from gestion.models import ErnestoUser
from django.contrib.auth.admin import UserAdmin
class UserProfileInline(admin.StackedInline):
model = ErnestoUser
def ProfileInfo(field, short_description, boolean=False):
def getter(self):
try:
return getattr(self.profile, field)
except ErnestoUser.DoesNotExist:
return ""
getter.short_description = short_description
getter.boolean = boolean
return getter
User.profile_phone = ProfileInfo("phone", "Telephone")
User.profile_instru = ProfileInfo("instru", "Instrument joué")
User.profile_is_ern = ProfileInfo("is_ernesto", "Ernestophoniste")
User.profile_is_chef = ProfileInfo("is_chef", "Chef Fanfare")
class UserProfileAdmin(UserAdmin):
list_display = ('username', 'first_name', 'last_name', 'email', 'profile_phone', 'profile_instru', 'profile_is_ern', 'profile_is_chef',)
list_display_links = ('username', 'email', 'first_name', 'last_name',)
list_filter = ('profile__instru',)
ordering = ('username',)
search_fields = ('username', 'first_name', 'last_name', 'profile__phone', 'profile__instru',)
inlines = [ UserProfileInline, ]
admin.site.unregister(User)
admin.site.unregister(Group)
admin.site.register(User, UserProfileAdmin)
# Register your models here.