generated from ieeeuoft/hackathon-template
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadmin.py
123 lines (98 loc) · 3.1 KB
/
admin.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
from django.contrib import admin
from django.contrib.auth.admin import UserAdmin
from django.db.models import Count
from import_export import resources
from import_export.admin import ExportMixin
from event.models import Profile, Team as EventTeam, User, UserActivity
from hardware.admin import OrderInline
admin.site.unregister(User)
class UserResource(resources.ModelResource):
class Meta:
model = User
fields = (
"first_name",
"last_name",
"email",
"is_active",
"application__id",
"application__review__status",
)
export_order = tuple(fields)
def get_export_headers(self):
export_headers = [
"First Name",
"Last Name",
"Email",
"Account Confirmed",
"Application ID",
"Review Status",
]
return export_headers
@admin.register(User)
class EnhancedUser(ExportMixin, UserAdmin):
list_display = UserAdmin.list_display + (
"is_active",
"get_application_status",
"get_review_status",
)
resource_class = UserResource
def get_application_status(self, obj):
return "Applied" if obj.application.id is not None else "Not Applied"
get_application_status.short_description = "Application Status"
def get_review_status(self, obj):
return obj.application.review.status
get_review_status.short_description = "Review Status"
def get_queryset(self, request):
return (
super()
.get_queryset(request)
.select_related("application", "application__review")
)
def get_export_queryset(self, request):
return (
super()
.get_queryset(request)
.select_related("application", "application__review")
)
@admin.register(EventTeam)
class EventTeamAdmin(admin.ModelAdmin):
list_display = (
"id",
"team_code",
"get_members_count",
"created_at",
)
list_display_links = ("id", "team_code")
search_fields = (
"id",
"team_code",
)
inlines = (OrderInline,)
def get_queryset(self, request):
return (
super()
.get_queryset(request)
.annotate(members_count=Count("profiles", distinct=True))
)
@admin.display(description="Members", ordering="Members")
def get_members_count(self, obj):
return obj.members_count
@admin.register(UserActivity)
class UserActivityAdmin(ExportMixin, admin.ModelAdmin):
list_display = (
"get_user_name",
"sign_in",
"lunch1",
"dinner1",
"breakfast2",
"lunch2",
)
def get_user_name(self, obj):
return f"{obj.user.first_name} {obj.user.last_name}"
get_user_name.short_description = "Name"
def get_queryset(self, request):
return super().get_queryset(request).select_related("user")
def get_export_queryset(self, request):
return super().get_queryset(request).select_related("user")
# Register your models here.
admin.site.register(Profile)