Opened 19 years ago

Closed 19 years ago

Last modified 18 years ago

#374 closed defect (fixed)

[patch] Filtering BooleanField does not work with SQLite

Reported by: davidschein@… Owned by: Adrian Holovaty
Component: contrib.admin Version:
Severity: major Keywords: sqlite, filters, booleanfield
Cc: Triage Stage: Unreviewed
Has patch: yes Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

When Django wants to filter on a bool, it passes the parameter value as 'True' or 'False', whereas SQLite expects a 1/0 or '1'/'0' or even a proper Python True/False. But the string containing 'True'/'False' is lost on it. I am not sure where to address this in the code. The sqlite adapted does not know about models, so main might be the best place for logic to look for backend mappings (which need to be added obviously.) Trivially, the following hack/patch gets it working for sqlite.

Index: main.py

===================================================================

--- main.py	(revision 537)

+++ main.py	(working copy)

@@ -251,7 +251,7 @@

                 lookup_val = request.GET.get(lookup_kwarg, None)
                 lookup_val2 = request.GET.get(lookup_kwarg2, None)
                 filter_template.append('<h3>By %s:</h3><ul>\n' % f.verbose_name)
-                for k, v in (('All', None), ('Yes', 'True'), ('No', 'False')):
+                for k, v in (('All', None), ('Yes', '1'), ('No', '0')):
                     filter_template.append('<li%s><a href="%s">%s</a></li>\n' % \
                         (((lookup_val == v and not lookup_val2) and ' class="selected"' or ''),
                         get_query_string(params, {lookup_kwarg: v}, [lookup_kwarg2]), k))

Change History (7)

comment:1 by Jacob, 19 years ago

milestone: Version 1.0
Summary: Filtering BooleanField does not work with SQLite [patch] Filtering BooleanField does not work with SQLite

comment:2 by Jacob, 19 years ago

David, do you have any way of testing to see if this patch works with MySQL/PostgreSQL? Seems like it should and I'll check it out when I get a chance, but if you can verify it works with other backends I'll check this fix in.

comment:3 by davidschein@…, 19 years ago

I am sorry but I do not have MySQL or PostgreSQL set up.

comment:4 by Adrian Holovaty, 19 years ago

Status: newassigned

I'll check it out.

comment:5 by Adrian Holovaty, 19 years ago

I've confirmed the patch works with Postgres. Testing MySQL next...

comment:6 by Adrian Holovaty, 19 years ago

Resolution: fixed
Status: assignedclosed

(In [804]) Fixed #374 -- Filtering by BooleanField now works in admin with SQLite. Thanks, davidschein

comment:7 by (none), 18 years ago

milestone: Version 1.0

Milestone Version 1.0 deleted

Note: See TracTickets for help on using tickets.
Back to Top