-
Notifications
You must be signed in to change notification settings - Fork 19
/
admin.py
126 lines (93 loc) · 3.11 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
124
125
126
from django import forms
from django.contrib import admin
from .constants import DAYS_OF_WEEK, OH_CHOICES, OH_TIMES
from .models import (
Event,
EventCategory,
Notice,
Officer,
Officership,
Person,
Politburo,
PolitburoMembership,
Semester,
Sponsor,
Sponsorship,
UcbClass,
)
admin.site.site_header = "CSUA Django Administration"
admin.site.site_title = "CSUA Administration"
admin.site.index_title = "Home"
admin.site.index_header = "Home"
class OfficershipAdminForm(forms.ModelForm):
office_hours = forms.CharField(widget=forms.Select(choices=OH_CHOICES))
tutor_subjects = forms.ModelMultipleChoiceField(
required=False, queryset=UcbClass.objects, widget=forms.CheckboxSelectMultiple
)
class SponsorshipInline(admin.TabularInline):
model = Sponsorship
ordering = ("sponsor__name",)
autocomplete_fields = ("sponsor",)
extra = 0
class OfficershipInline(admin.TabularInline):
form = OfficershipAdminForm
model = Officership
autocomplete_fields = ("officer",)
extra = 0
class PolitburoMembershipInline(admin.TabularInline):
model = PolitburoMembership
autocomplete_fields = ("person",)
extra = 0
@admin.register(EventCategory)
class EventCategoryAdmin(admin.ModelAdmin):
pass
@admin.register(Semester)
class SemesterAdmin(admin.ModelAdmin):
inlines = [OfficershipInline, PolitburoMembershipInline, SponsorshipInline]
autocomplete_fields = ("events",)
@admin.register(Officer)
class OfficerAdmin(admin.ModelAdmin):
inlines = [OfficershipInline]
list_display = ("person", "officer_since")
ordering = ("person",)
search_fields = (
"person__user__first_name",
"person__user__last_name",
"person__user__username",
)
@admin.register(Officership)
class OfficershipAdmin(admin.ModelAdmin):
list_display = ("semester", "officer", "office_hours", "blurb")
list_filter = ("semester", "officer")
autocomplete_fields = ("tutor_subjects",)
@admin.register(Person)
class PersonAdmin(admin.ModelAdmin):
ordering = ("user",)
list_display = ("user",)
search_fields = ("user__first_name", "user__last_name", "user__username")
@admin.register(UcbClass)
class UcbClassAdmin(admin.ModelAdmin):
search_fields = ("id",)
# Register your models here.
@admin.register(Event)
class EventAdmin(admin.ModelAdmin):
actions = ["duplicate_events", "enable_events", "disable_events"]
search_fields = ("name", "date")
def disable_events(modeladmin, request, queryset):
queryset.update(enabled=False)
def enable_events(modeladmin, request, queryset):
queryset.update(enabled=True)
def duplicate_events(modeladmin, request, queryset):
for event in queryset:
event.pk = None
event.save()
@admin.register(Politburo)
class PolituburoAdmin(admin.ModelAdmin):
inlines = [PolitburoMembershipInline]
@admin.register(Sponsor)
class SponsorAdmin(admin.ModelAdmin):
inlines = [SponsorshipInline]
search_fields = ("name",)
@admin.register(Notice)
class NoticeAdmin(admin.ModelAdmin):
list_display = ("expires", "text")