@@ -659,6 +659,32 @@ def get_changelist(self, request, **kwargs):
659
659
from django .contrib .admin .views .main import ChangeList
660
660
return ChangeList
661
661
662
+ def get_changelist_instance (self , request ):
663
+ """
664
+ Return a `ChangeList` instance based on `request`. May raise
665
+ `IncorrectLookupParameters`.
666
+ """
667
+ list_display = self .get_list_display (request )
668
+ list_display_links = self .get_list_display_links (request , list_display )
669
+ # Add the action checkboxes if any actions are available.
670
+ if self .get_actions (request ):
671
+ list_display = ['action_checkbox' ] + list (list_display )
672
+ ChangeList = self .get_changelist (request )
673
+ return ChangeList (
674
+ request ,
675
+ self .model ,
676
+ list_display ,
677
+ list_display_links ,
678
+ self .get_list_filter (request ),
679
+ self .date_hierarchy ,
680
+ self .get_search_fields (request ),
681
+ self .get_list_select_related (request ),
682
+ self .list_per_page ,
683
+ self .list_max_show_all ,
684
+ self .list_editable ,
685
+ self ,
686
+ )
687
+
662
688
def get_object (self , request , object_id , from_field = None ):
663
689
"""
664
690
Return an instance matching the field and value provided, the primary
@@ -1522,26 +1548,8 @@ def changelist_view(self, request, extra_context=None):
1522
1548
if not self .has_change_permission (request , None ):
1523
1549
raise PermissionDenied
1524
1550
1525
- list_display = self .get_list_display (request )
1526
- list_display_links = self .get_list_display_links (request , list_display )
1527
- list_filter = self .get_list_filter (request )
1528
- search_fields = self .get_search_fields (request )
1529
- list_select_related = self .get_list_select_related (request )
1530
-
1531
- # Check actions to see if any are available on this changelist
1532
- actions = self .get_actions (request )
1533
- if actions :
1534
- # Add the action checkboxes if there are any actions available.
1535
- list_display = ['action_checkbox' ] + list (list_display )
1536
-
1537
- ChangeList = self .get_changelist (request )
1538
1551
try :
1539
- cl = ChangeList (
1540
- request , self .model , list_display ,
1541
- list_display_links , list_filter , self .date_hierarchy ,
1542
- search_fields , list_select_related , self .list_per_page ,
1543
- self .list_max_show_all , self .list_editable , self ,
1544
- )
1552
+ cl = self .get_changelist_instance (request )
1545
1553
except IncorrectLookupParameters :
1546
1554
# Wacky lookup parameters were given, so redirect to the main
1547
1555
# changelist page, without parameters, and pass an 'invalid=1'
@@ -1562,6 +1570,7 @@ def changelist_view(self, request, extra_context=None):
1562
1570
action_failed = False
1563
1571
selected = request .POST .getlist (helpers .ACTION_CHECKBOX_NAME )
1564
1572
1573
+ actions = self .get_actions (request )
1565
1574
# Actions with no confirmation
1566
1575
if (actions and request .method == 'POST' and
1567
1576
'index' in request .POST and '_save' not in request .POST ):
0 commit comments