Skip to content

Commit acc0592

Browse files
author
nikitatonkoshkur
committed
Added support for Django 3.1 admin sidebar
1 parent 38283ae commit acc0592

File tree

2 files changed

+10
-4
lines changed

2 files changed

+10
-4
lines changed

README.rst

+2
Original file line numberDiff line numberDiff line change
@@ -39,6 +39,8 @@ Features
3939

4040
* Rename individual models in the app list. e.g. rename ``auth.User`` from ``User`` to ``Staff``
4141

42+
* Adds all of the above to Django 3.1 Admin Sidebar
43+
4244

4345
Documentation
4446
-------------

admin_reorder/middleware.py

+8-4
Original file line numberDiff line numberDiff line change
@@ -151,13 +151,17 @@ def process_template_response(self, request, response):
151151
# or app_list view, bail out!
152152
return response
153153

154-
try:
154+
if 'app_list' in response.context_data:
155155
app_list = response.context_data['app_list']
156-
except KeyError:
157-
# there is no app_list! nothing to reorder
156+
context_key = 'app_list'
157+
# handle django 3.1 sidebar
158+
elif 'available_apps' in response.context_data:
159+
app_list = response.context_data['available_apps']
160+
context_key = 'available_apps'
161+
else: # nothing to reorder, return response
158162
return response
159163

160164
self.init_config(request, app_list)
161165
ordered_app_list = self.get_app_list()
162-
response.context_data['app_list'] = ordered_app_list
166+
response.context_data[context_key] = ordered_app_list
163167
return response

0 commit comments

Comments
 (0)