#19318: Admin's SimpleListFilter option not being displayed as selected if the
lookup's first element is not a string
-------------------------------+--------------------
     Reporter:  sebasmagri     |      Owner:  nobody
         Type:  Bug            |     Status:  new
    Component:  contrib.admin  |    Version:  1.4
     Severity:  Normal         |   Keywords:
 Triage Stage:  Unreviewed     |  Has patch:  1
Easy pickings:  1              |      UI/UX:  1
-------------------------------+--------------------
 I had the following lookups method for a SimpleListFilter:

 {{{
 def lookups(self, request, model_admin):
     return set(itertools.chain(*[
         [(o.deliverable.id, o.deliverable.name)
          for o in user.orders.all()]
         for user in model_admin.queryset(request).all()
     ]))
 }}}

 In this case, the filters in the change list didn't display the option as
 selected on activation.

 Changing the above code to

 {{{
 def lookups(self, request, model_admin):
     return set(itertools.chain(*[
         [(str(o.deliverable.id), o.deliverable.name)
          for o in user.orders.all()]
         for user in model_admin.queryset(request).all()
     ]))
 }}}

 Fixed the issue.

 This seems to be caused by
 
[https://github.com/django/django/blob/master/django/contrib/admin/filters.py#L105
 django/contrib/admin/filters.py:105], where

 {{{
 yield {
     'selected': self.value() == lookup,
     'query_string': cl.get_query_string({
          self.parameter_name: lookup,
     }, []),
     'display': title,
 }
 }}}

 Might be

 {{{
 yield {
     'selected': self.value() == str(lookup),
     'query_string': cl.get_query_string({
          self.parameter_name: lookup,
     }, []),
     'display': title,
 }
 }}}

 I've created [https://github.com/django/django/pull/538 a pull request] at
 GitHub with this change.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/19318>
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 post to this group, send email to django-updates@googlegroups.com.
To unsubscribe from this group, send email to 
django-updates+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.


Reply via email to