[Models] update migration files for user models
[mygpo.git] / mygpo / users / admin.py
blob3aec8c1c7a103f049871fe799b5d6c9350bfc3d3
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):
10 model = UserProfile
11 can_delete = False
12 verbose_name_plural = 'profile'
14 # Define a new User admin
15 class UserAdmin(UserAdmin):
16 inlines = (UserProfileInline, )
18 list_display = ('username', 'email', 'is_active', 'is_staff',
19 'is_superuser', 'date_joined', 'last_login')
21 # Re-register UserAdmin
22 admin.site.unregister(User)
23 admin.site.register(User, UserAdmin)
26 @admin.register(Client)
27 class ClientAdmin(admin.ModelAdmin):
28 """ Admin page for clients """
30 # configuration for the list view
31 list_display = ('name', 'user', 'uid', 'type', )
33 # fetch the client's user for the fields in list_display
34 list_select_related = ('user', )
36 list_filter = ('type', )
37 search_fields = ('name', 'uid', 'user__username', )
39 raw_id_fields = ('user', )
42 @admin.register(SyncGroup)
43 class SyncGroupAdmin(admin.ModelAdmin):
44 """ Admin page for SyncGroups """
46 list_display = ('user', 'num_clients')
48 def num_clients(self, group):
49 """ Numer of clients that belong to this group """
50 return Client.objects.filter(sync_group=group).count()