Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP

Loading…

Coerce lookup to str in admin's SimpleListFilter.choices detection of selected choice. #538

Closed
wants to merge 2 commits into from

1 participant

@sebasmagri

When a non-string value is used for the lookup tuple first element in SimpleListFilter.lookups, the comparison with SimpleListFilter.value() will fail, and the option will not be rendered as selected in the admin's changelist.

sebasmagri added some commits
@sebasmagri sebasmagri Coerce lookup to str in SimpleListFilter.choices
When a non-string value is used for the lookup tuple first element in SimpleListFilter.lookups, the comparison with SimpleListFilter.value() will fail, and the option will not be rendered as selected in the admin's changelist.
42ad9fb
@sebasmagri sebasmagri Use force_unicode instead of str
Use django.utils.encoding.force_unicode instead of str in SimpleListFilter.choices when coercing lookups.
0af0680
@sebasmagri sebasmagri closed this
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on Nov 18, 2012
  1. @sebasmagri

    Coerce lookup to str in SimpleListFilter.choices

    sebasmagri authored
    When a non-string value is used for the lookup tuple first element in SimpleListFilter.lookups, the comparison with SimpleListFilter.value() will fail, and the option will not be rendered as selected in the admin's changelist.
  2. @sebasmagri

    Use force_unicode instead of str

    sebasmagri authored
    Use django.utils.encoding.force_unicode instead of str in SimpleListFilter.choices when coercing lookups.
This page is out of date. Refresh to see the latest.
Showing with 2 additions and 2 deletions.
  1. +2 −2 django/contrib/admin/filters.py
View
4 django/contrib/admin/filters.py
@@ -9,7 +9,7 @@
from django.db import models
from django.core.exceptions import ImproperlyConfigured, ValidationError
-from django.utils.encoding import smart_text
+from django.utils.encoding import smart_text, force_unicode
from django.utils.translation import ugettext_lazy as _
from django.utils import timezone
from django.contrib.admin.util import (get_model_from_relation,
@@ -102,7 +102,7 @@ def choices(self, cl):
}
for lookup, title in self.lookup_choices:
yield {
- 'selected': self.value() == lookup,
+ 'selected': self.value() == force_unicode(lookup),
'query_string': cl.get_query_string({
self.parameter_name: lookup,
}, []),
Something went wrong with that request. Please try again.