#29618: using query parameters to filter by boolean causes validation error due 
to
lowercase true/false
-------------------------------+--------------------------------------
     Reporter:  levi schubert  |                    Owner:  nobody
         Type:  Bug            |                   Status:  closed
    Component:  Uncategorized  |                  Version:  2.0
     Severity:  Normal         |               Resolution:  invalid
     Keywords:  filter         |             Triage Stage:  Unreviewed
    Has patch:  0              |      Needs documentation:  0
  Needs tests:  0              |  Patch needs improvement:  0
Easy pickings:  0              |                    UI/UX:  0
-------------------------------+--------------------------------------
Changes (by Carlton Gibson):

 * status:  new => closed
 * resolution:   => invalid


Comment:

 It’s hard to know from your description exactly what you’re doing but I’d
 guess you’re just taking the **string** value contained in `request.GET`
 and trying to filter the model field on that.

 If so, this won’t work, since you need to pass a boolean `True` or `False`
 to a boolean field.

 I don’t understand the point about `title()` at all, since the string
 `’False’` isn’t a boolean either.

 It would have been helpful if you’d have provided a complete reproduce and
 the exact error, plus traceback.

 However, the correct approach here it to pass `request.GET` into a form in
 order to validate the raw (user submitted) data and convert it to
 appropriate types, before using the value from the form’s `cleaned_data`
 in order to filter your queryset.

 There’s a bit of biolerplate involved in this. You might want to check out
 [https://django-filter.readthedocs.io/en/master/ Django Filter], that
 wraps this up.

 I’m going to close this as a usage question. If I’ve missed something and
 there’s a reproducible big here please do follow-up with details and we
 can re-open.

-- 
Ticket URL: <https://code.djangoproject.com/ticket/29618#comment:2>
Django <https://code.djangoproject.com/>
The Web framework for perfectionists with deadlines.

-- 
You received this message because you are subscribed to the Google Groups 
"Django updates" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to django-updates+unsubscr...@googlegroups.com.
To post to this group, send email to django-updates@googlegroups.com.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-updates/071.446ce2294f662e7f9bfacac96a27925e%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to