Django

Code

Ticket #374 (closed: fixed)

Opened 3 years ago

Last modified 2 years ago

[patch] Filtering BooleanField does not work with SQLite

Reported by: davidschein@alumni.tufts.edu Assigned to: adrian
Milestone: Component: django.contrib.admin
Version: Keywords: sqlite, filters, booleanfield
Cc: Triage Stage: Unreviewed
Has patch: 1 Needs documentation: 0
Needs tests: 0 Patch needs improvement: 0

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

Change History

09/25/05 17:28:13 changed by jacob

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

09/30/05 08:53:48 changed 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.

10/03/05 10:01:38 changed by davidschein@alumni.tufts.edu

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

10/03/05 10:02:36 changed by adrian

  • status changed from new to assigned.

I'll check it out.

10/08/05 15:18:16 changed by adrian

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

10/08/05 15:23:12 changed by adrian

  • status changed from assigned to closed.
  • resolution set to fixed.

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

01/17/07 16:12:17 changed by

  • milestone deleted.

Milestone Version 1.0 deleted


Add/Change #374 ([patch] Filtering BooleanField does not work with SQLite )




Change Properties
Action