Code

Opened 9 years ago

Closed 9 years ago

Last modified 7 years ago

#374 closed defect (fixed)

[patch] Filtering BooleanField does not work with SQLite

Reported by: davidschein@… Owned by: adrian
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: UI/UX:

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))

Attachments (0)

Change History (7)

comment:1 Changed 9 years ago by jacob

  • milestone set to Version 1.0
  • Summary changed from Filtering BooleanField does not work with SQLite to [patch] Filtering BooleanField does not work with SQLite

comment:2 Changed 9 years ago by jacob

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 Changed 9 years ago by davidschein@…

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

comment:4 Changed 9 years ago by adrian

  • Status changed from new to assigned

I'll check it out.

comment:5 Changed 9 years ago by adrian

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

comment:6 Changed 9 years ago by adrian

  • Resolution set to fixed
  • Status changed from assigned to closed

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

comment:7 Changed 7 years ago by anonymous

  • milestone Version 1.0 deleted

Milestone Version 1.0 deleted

Add Comment

Modify Ticket

Change Properties
<Author field>
Action
as closed
as The resolution will be set. Next status will be 'closed'
The resolution will be deleted. Next status will be 'new'
Author


E-mail address and user name can be saved in the Preferences.

 
Note: See TracTickets for help on using tickets.