#29519: Django admin actions: _selected_action disregarded when `difference` is
applied to queryset via filters
-------------------------------------------+------------------------
               Reporter:  Andreas Galazis  |          Owner:  nobody
                   Type:  Uncategorized    |         Status:  new
              Component:  Uncategorized    |        Version:  2.0
               Severity:  Normal           |       Keywords:
           Triage Stage:  Unreviewed       |      Has patch:  0
    Needs documentation:  0                |    Needs tests:  0
Patch needs improvement:  0                |  Easy pickings:  0
                  UI/UX:  0                |
-------------------------------------------+------------------------
 I have an admin with filters where one of them is:
 {{{
 #!div style="font-size: 80%"
 Code highlighting:
   {{{#!python
 class NegatedMyFiledFilter(MyFieldListFilter):
     title = ('excluded Fields')
     parameter_name = 'nonField'

     def queryset(self, request, queryset):
         if self.values():
             queryset_to_negate = super(
                 NegatedMyFieldFilter, self
             ).queryset(request, queryset)
             return queryset.difference(queryset_to_negate)
   }}}
 }}}
 Where MyFieldListFilter is a filter that extends admin.SimpleListFilter
 When the above filter is applied(alone or in combination with others)
 _selected_action is not respected when applying an action and as a result
 actions get applied to all records, not  just the selected ones
 As a hack I ended up doing in one of my custom actions :
 {{{
 #!div style="font-size: 80%"
 Code highlighting:
   {{{#!python
     qs_ids = queryset.values_list('pk', flat=True)
     selected_ids = request.POST.getlist('_selected_action',qs_ids)
     return TimeSheet.objects.filter(
         pk__in=qs_ids,
     ).filter(pk__in=selected_ids).update(my_flag=True)
   }}}
 }}}
 but I was expecting the framework to do the second filtering for me

-- 
Ticket URL: <https://code.djangoproject.com/ticket/29519>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/051.cb50618523b36326ec7ca4ff5a086ca8%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to