Note that there are some explanatory texts on larger screens.

plurals
  1. POIn Djano checkbox i am getting False value though POST data shows checbox has been checked?
    primarykey
    data
    text
    <p>I am having a boolean field in my model which disaply as checkbox in view and I am running custom validations upon it. However i am always getting its value as "False" in my model form's clean method even user checks that check box, i read somewher that django automatically converts value as False.</p> <p>Can someone guide me in my clean method how should i check whether checkbox is checked or not? Any help on this issue will be appreciated</p> <p>My model is as follows:- </p> <pre><code>discard_word = models.BooleanField(max_length=30) </code></pre> <p>My modelform view as follows:- </p> <pre><code>if request.method == 'POST': form_with_post = FormSet(request.POST,queryset=page_query) if form_with_post.is_valid(): </code></pre> <p>My form as follows:- </p> <pre><code>class Un_Verified_bn_in_form(ModelForm): def __init__(self, *args, **kwargs): super(Un_Verified_bn_in_form, self).__init__(*args, **kwargs) instance = getattr(self, 'instance', None) if instance and instance.pk: self.fields['phrase'].required = False self.fields['phrase'].widget.attrs['readonly'] = True self.fields['id'].widget.attrs['readonly'] = True self.fields['id'].required = False self.fields['alternate_phrase'].required = False #self.fields['discard_word'].required = False def clean(self): cleaned_data = self.cleaned_data replace_phrase = cleaned_data.get("alternate_phrase") discard_word_val = cleaned_data.get("discard_word") if (replace_phrase == u'' or replace_phrase == None) and (discard_word_val == False ): raise ValidationError('You need to select atleast one field') return cleaned_data class Meta: model = Un_Verified_bn_in fields = ('id','phrase','alternate_phrase','discard_word') exclude = ('time','verified_by_usr','verified_by_admin','author') </code></pre>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload