#22406: Inconsistent way to parse boolean value from posted data
--------------------------+--------------------------------------
Reporter: xiaowl@… | Owner: nobody
Type: Bug | Status: closed
Component: Forms | Version: 1.6
Severity: Normal | Resolution: needsinfo
Keywords: | Triage Stage: Unreviewed
Has patch: 1 | Needs documentation: 0
Needs tests: 0 | Patch needs improvement: 0
Easy pickings: 0 | UI/UX: 0
--------------------------+--------------------------------------
Comment (by cirosantilli):
I am doing something like this:
- a single AJAX view creates or deletes user up or down votes for posts.
If the vote already exists, it is deleted or modified.
- there are two types of vote differentiated by a Booleanfield
(application specific, difficult to explain), let's call them typeTrue and
typeFalse
- each user can do a single vote of each type (typeTrue and typeFalse)
either up or down
Now the view works as follows:
- check if the vote of a given type already exists for a given user. This
is an unique triple:
`Vote.filter(booleanfield=request.POST['booleanfield'])`
- if yes, delete it
- else, get the existing vote `vote`, and create or update it. This means
a form validation: `form = Vote(request.POST, instance=vote)`
So now, what should my AJAX send?
If nothing, as a form submission checkbox would on `False`, the existing
vote is not found as it should to be deleted.
If `'0'`, the form always gives me `True`.
I think `'false'` would work because it works for both, but it feels
inconsistent. Why `'0'` does not work as well?
Actual code: https://github.com/cirosantilli/free-books-django-
raw/blob/d4cb03d61a6f0c19ac7333ee1099e679e0acef21/free_books/views.py#L280
--
Ticket URL: <https://code.djangoproject.com/ticket/22406#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 [email protected].
To post to this group, send email to [email protected].
To view this discussion on the web visit
https://groups.google.com/d/msgid/django-updates/075.47c695048d58017298984ec95c94abf0%40djangoproject.com.
For more options, visit https://groups.google.com/d/optout.