-
Notifications
You must be signed in to change notification settings - Fork 27
Expand file tree
/
Copy pathadmin.py
More file actions
53 lines (40 loc) · 1.54 KB
/
admin.py
File metadata and controls
53 lines (40 loc) · 1.54 KB
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
from adminsortable2.admin import SortableAdminMixin
from django.contrib import admin
from django.utils.encoding import force_text
from .models import Event, Section
class IsArchivedListFilter(admin.SimpleListFilter):
title = 'Archived?'
parameter_name = 'is_removed'
def lookups(self, request, model_admin):
return (
(True, 'Yes'),
)
def choices(self, changelist):
yield {
'selected': self.value() is None,
'query_string': changelist.get_query_string({}, [self.parameter_name]),
'display': 'No',
}
for lookup, title in self.lookup_choices:
yield {
'selected': self.value() == force_text(lookup),
'query_string': changelist.get_query_string({self.parameter_name: lookup}, []),
'display': title,
}
def queryset(self, request, queryset):
if self.value():
return queryset.filter(is_removed=True)
return queryset.filter(is_removed=False)
class EventAdmin(admin.ModelAdmin):
search_fields = ('name', 'location',)
list_filter = (IsArchivedListFilter,)
list_display = ('name', 'location', 'schedule',)
def get_queryset(self, request):
return Event.all_objects.all()
@admin.register(Section)
class SectionAdmin(SortableAdminMixin, admin.ModelAdmin):
search_fields = ('name',)
list_filter = (IsArchivedListFilter,)
def get_queryset(self, request):
return Section.all_objects.all()
admin.site.register(Event, EventAdmin)