I'm trying to extract the data from my django form in a view. I'm using request.POST.get(). I'm aware that form.cleaned_data[] is preferred, but I can't use it because it is incompatible with Ajax, which I need for my form (form.is_valid() always returns false; if anyone has a way around this, that'd be great too.)
Anyways, my form has a few BooleanFields:
distributive = forms.BooleanField(widget=forms.CheckboxInput(attrs={'id':'distributive'}),required=False)
transitivity = forms.BooleanField(widget=forms.CheckboxInput(attrs={'id':'transitivity'}),required=False)
Whether these fields are "checked" or not by the user, request.POST.get() is returning 'on'.
Here is my code from the view:
def post(self, request):
form = VerbQueryForm(request.POST)
transitivity = request.POST.get('transitivity')
distributive = request.POST.get('distributive')
What I'm looking for is either:
A. (Ideal, but not the point of this post) A way to use form.is_valid() and cleaned_data with Ajax
B. A way to get request.POST.get() to return boolean values
C. A way to get request.POST.get() to consistently return strings 'true' and 'false' (or any two strings), so that I can work around the problem using something like:
transitivity = request.POST.get('transitivity') == 'true'
Any help would be much appreciated. Thanks!