Bump babel from 2.9.1 to 2.10.3
[mygpo.git] / mygpo / users / admin.py
blobe6c2a930261910799891fc3223828be1611c5730
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"
15 # Define a new User admin
16 class UserAdmin(UserAdmin):
17 inlines = (UserProfileInline,)
19 list_display = (
20 "username",
21 "email",
22 "is_active",
23 "is_staff",
24 "is_superuser",
25 "date_joined",
26 "last_login",
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