1 from django
.contrib
import admin
2 from django
.contrib
.auth
.admin
import UserAdmin
3 from django
.contrib
.auth
.models
import User
5 from mygpo
.users
.models
import UserProfile
, Client
, SyncGroup
7 # Define an inline admin descriptor for the UserProfile model
8 # which acts a bit like a singleton
9 class UserProfileInline(admin
.StackedInline
):
12 verbose_name_plural
= "profile"
15 # Define a new User admin
16 class UserAdmin(UserAdmin
):
17 inlines
= (UserProfileInline
,)
30 # Re-register UserAdmin
31 admin
.site
.unregister(User
)
32 admin
.site
.register(User
, UserAdmin
)
35 @admin.register(Client
)
36 class ClientAdmin(admin
.ModelAdmin
):
37 """Admin page for clients"""
39 # configuration for the list view
40 list_display
= ("name", "user", "uid", "type")
42 # fetch the client's user for the fields in list_display
43 list_select_related
= ("user",)
45 list_filter
= ("type",)
46 search_fields
= ("name", "uid", "user__username")
48 raw_id_fields
= ("user",)
50 show_full_result_count
= False
53 @admin.register(SyncGroup
)
54 class SyncGroupAdmin(admin
.ModelAdmin
):
55 """Admin page for SyncGroups"""
57 list_display
= ("user", "num_clients")
59 def num_clients(self
, group
):
60 """Numer of clients that belong to this group"""
61 return Client
.objects
.filter(sync_group
=group
).count()
63 show_full_result_count
= False