Fix for filtering using __int on boolean fields.

This commit is contained in:
Chris Church 2013-08-13 20:19:53 -04:00
parent 22af7cf6b0
commit 718b566a03
2 changed files with 8 additions and 0 deletions

View File

@ -61,6 +61,7 @@ class FieldLookupBackend(BaseFilterBackend):
return field
def to_python_boolean(self, value, allow_none=False):
value = unicode(value)
if value.lower() in ('true', '1'):
return True
elif value.lower() in ('false', '0'):
@ -71,6 +72,7 @@ class FieldLookupBackend(BaseFilterBackend):
raise ValueError(u'Unable to convert "%s" to boolean' % unicode(value))
def to_python_related(self, value):
value = unicode(value)
if value.lower() in ('none', 'null'):
return None
else:

View File

@ -406,6 +406,12 @@ class UsersTest(BaseTest):
url = '%s?is_superuser=notatbool' % base_url
self.check_get_list(url, self.super_django_user, base_qs, expect=400)
# Filter by custom __int suffix on boolean field.
url = '%s?is_superuser__int=1' % base_url
qs = base_qs.filter(is_superuser=True)
self.assertTrue(qs.count())
self.check_get_list(url, self.super_django_user, qs)
# Filter by is_staff (field not exposed via API). FIXME: Should
# eventually not be allowed!
url = '%s?is_staff=true' % base_url