﻿id	summary	reporter	owner	description	type	status	component	version	severity	resolution	keywords	cc	stage	has_patch	needs_docs	needs_tests	needs_better_patch	easy	ui_ux
19318	Admin's SimpleListFilter option not being displayed as selected if the lookup's first element is not a string	Sebastián Magrí	nobody	"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."	Bug	closed	contrib.admin	1.4	Normal	fixed			Accepted	1	0	1	1	1	0
