|
1 | 1 | from django.contrib import admin |
| 2 | +from django.db.models import Count, Q |
2 | 3 |
|
3 | 4 | from .models import UserProfile |
4 | 5 |
|
5 | 6 |
|
6 | 7 | class UserProfileAdmin(admin.ModelAdmin): |
7 | | - list_display = ("user",) |
| 8 | + list_display = ( |
| 9 | + "user", |
| 10 | + "notify_all_author", |
| 11 | + "notify_all_reviewer", |
| 12 | + "notify_all_committer", |
| 13 | + "show_relative_timestamps", |
| 14 | + ) |
| 15 | + list_filter = ( |
| 16 | + "notify_all_author", |
| 17 | + "notify_all_reviewer", |
| 18 | + "notify_all_committer", |
| 19 | + "show_relative_timestamps", |
| 20 | + ) |
| 21 | + search_fields = ("user__username", "user__first_name", "user__last_name") |
| 22 | + |
| 23 | + def changelist_view(self, request, extra_context=None): |
| 24 | + stats = UserProfile.objects.aggregate( |
| 25 | + total=Count("id"), |
| 26 | + author_on=Count("id", filter=Q(notify_all_author=True)), |
| 27 | + author_off=Count("id", filter=Q(notify_all_author=False)), |
| 28 | + reviewer_on=Count("id", filter=Q(notify_all_reviewer=True)), |
| 29 | + reviewer_off=Count("id", filter=Q(notify_all_reviewer=False)), |
| 30 | + committer_on=Count("id", filter=Q(notify_all_committer=True)), |
| 31 | + committer_off=Count("id", filter=Q(notify_all_committer=False)), |
| 32 | + timestamps_on=Count("id", filter=Q(show_relative_timestamps=True)), |
| 33 | + timestamps_off=Count("id", filter=Q(show_relative_timestamps=False)), |
| 34 | + ) |
| 35 | + extra_context = extra_context or {} |
| 36 | + extra_context["notification_stats"] = stats |
| 37 | + return super().changelist_view(request, extra_context=extra_context) |
8 | 38 |
|
9 | 39 |
|
10 | 40 | admin.site.register(UserProfile, UserProfileAdmin) |
0 commit comments