@@ -117,28 +117,28 @@ def render_card(self, card: "Card"):
117
117
118
118
class AdminListView (AdminView ):
119
119
template_name = "admin/list.html"
120
- list_fields : list
121
- list_actions : dict [str ] = {}
122
- list_filters : list [str ] = []
120
+ fields : list
121
+ actions : dict [str ] = {}
122
+ filters : list [str ] = []
123
123
page_size = 100
124
124
show_search = False
125
125
126
126
def get_context (self ):
127
127
context = super ().get_context ()
128
128
129
- list_filter = self .request .GET .get ("filter" , "" )
129
+ # Make this available on self for usage in get_objects and other methods
130
+ self .filter = self .request .GET .get ("filter" , "" )
130
131
131
132
objects = self .get_objects ()
132
- objects = self .filter_objects (list_filter , objects )
133
133
134
134
context ["paginator" ] = Paginator (objects , self .page_size )
135
135
context ["page" ] = context ["paginator" ].get_page (self .request .GET .get ("page" , 1 ))
136
136
context ["objects" ] = context ["page" ] # alias
137
- context ["list_fields" ] = self .list_fields
138
- context ["list_actions" ] = self .list_actions
137
+ context ["fields" ] = self .get_fields ()
138
+ context ["actions" ] = self .get_actions ()
139
+ context ["filters" ] = self .get_filters ()
139
140
140
- context ["list_filters" ] = self .list_filters
141
- context ["list_filter" ] = list_filter
141
+ context ["active_filter" ] = self .filter
142
142
143
143
# Implement search yourself in get_objects
144
144
context ["search_query" ] = self .request .GET .get ("search" , "" )
@@ -155,8 +155,9 @@ def get_context(self):
155
155
156
156
def post (self ) -> HttpResponse :
157
157
action_key = self .request .POST .get ("action_key" )
158
- if action_key and action_key in self .list_actions :
159
- action_callable = self .list_actions [action_key ]
158
+ actions = self .get_actions ()
159
+ if action_key and action_key in actions :
160
+ action_callable = actions [action_key ]
160
161
if isinstance (action_callable , str ):
161
162
action_callable = getattr (self , action_callable )
162
163
return action_callable (self .request .POST .getlist ("action_pks" ))
@@ -166,9 +167,14 @@ def post(self) -> HttpResponse:
166
167
def get_objects (self ) -> list :
167
168
return []
168
169
169
- def filter_objects (self , filter_name : str , objects : list ):
170
- """Implement custom object filters here by looking at filter name"""
171
- return objects
170
+ def get_fields (self ) -> list :
171
+ return self .fields
172
+
173
+ def get_actions (self ) -> dict [str ]:
174
+ return self .actions
175
+
176
+ def get_filters (self ) -> list [str ]:
177
+ return self .filters
172
178
173
179
def get_object_field (self , obj , field : str ):
174
180
# Try basic dict lookup first
0 commit comments