title: How to apply condition on django boolean field?
body: <p>I am working on an multi-vendor Django base E-commerce project. And I would like to implement a radio button base selection, like when a user add an item to cart I want him/her to choose (yes or no). Is this gift? when a user click on yes, I need to show a message input field where he/she can put custom message to print on item. There are multiple items in cart. Can Anyone guide me how to do this in django? Thank you in advance.</p>
  <p><strong>Update</strong> :
  I have worked out javascript thing but form is not submitting in view post method. Checkout button does nothing on clicking.
  <div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-js lang-js prettyprint-override"><code>function hideShowGiftField(btnId, msgFieldId) {
              let btn = document.getElementById(btnId)
              let msgField = document.getElementById(msgFieldId)
              if (btn.value === 'yes') {
                  msgField.type = 'text'
              } else if (btn.value === 'no') {
                  msgField.type = 'hidden'
              }
          }
  
          function hideShowEngravingField(btnId, engravingFieldId) {
              let btn = document.getElementById(btnId)
              let engravingField = document.getElementById(engravingFieldId)
              if (btn.value === 'yes') {
                  engravingField.type = 'text'
              } else if (btn.value === 'no') {
                  engravingField.type = 'hidden'
              }
          }</code></pre>
  <pre class="snippet-code-html lang-html prettyprint-override"><code>&lt;form action="{% url 'cart_detail' %}" method="post"&gt;
  {% csrf_token %}
  &lt;section&gt;
      &lt;div class="container"&gt;
          &lt;div class=""&gt;
              &lt;h2 class="review-cart-desktop"&gt;Review Cart&lt;/h2&gt;
              &lt;hr&gt;
              &lt;h2 class="review-cart"&gt;Review Cart&lt;/h2&gt;
              &lt;div class="row d-flex justify-content-center"&gt;
                  &lt;div class="col-8"&gt;
                      &lt;h4 class="mx-2 font-weight-bold"&gt;Item&lt;/h4&gt;
                  &lt;/div&gt;
                  &lt;div class="col-4"&gt;
                      &lt;div class="row text-center header-names"&gt;
                          &lt;div class="col-md-6"&gt;
                              &lt;h6 class="mt-2 text-center font-weight-bold"&gt;Quantity&lt;/h6&gt;
                          &lt;/div&gt;
                          &lt;div class="col-md-6"&gt;
                              &lt;h6 class="mt-2 text-center font-weight-bold"&gt;Price&lt;/h6&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
              &lt;hr&gt;
              {% for item in cart_items %}
                  &lt;div class="row d-flex justify-content-center"&gt;
                      &lt;div class="col-8 col-xs-12"&gt;
                          &lt;div class="row d-flex"&gt;
                              &lt;div class="book"&gt;&lt;img src="{{ item.variant.first.product.main_image.url }}"
                                                     alt="{{ item.variant.first.product.name }}"
                                                     class="book-img"&gt;
                              &lt;/div&gt;
                              &lt;div class="my-auto flex-column d-flex pad-left"&gt;
                                  &lt;h6 class="mob-text-item"
                                      style="text-transform: capitalize"&gt;{{ item.variant.first.product.name }}&lt;/h6&gt;
                                  {% for variant in item.variant.all %}
                                      &lt;p class="mob-text"&gt;{{ variant|capfirst }}&lt;/p&gt;
                                  {% endfor %}
                                  {#                                            &lt;p class="mob-text mob-text-custom"&gt;&lt;a href=""&gt;View Custom Design&lt;/a&gt;&lt;/p&gt;#}
                              &lt;/div&gt;
                          &lt;/div&gt;
                          &lt;div class="col-8 complete-row-input" style="margin-left: 150px;"&gt;
                              &lt;div class="row"&gt;
                                  &lt;div class="col-8"&gt;
                                      &lt;p style="font-size: 20px;"&gt;Is This is A Gift?&lt;/p&gt;
                                  &lt;/div&gt;
                                  &lt;div class="col-4"&gt;
                                      &lt;div class="d-flex" style="margin-left:15px ;"&gt;
                                          &lt;label for="gift_yes_{{ item.id }}"&gt;Yes&lt;/label&gt;&lt;input type="radio"
                                                                                                id="gift_yes_{{ item.id }}"
                                                                                                onchange="hideShowGiftField(this.id, 'custom-message-{{ item.id }}')"
                                                                                                name="{{ item.variant.first.product.name }}_gift"
                                                                                                value="yes"
                                                                                                class="mt-1 radio-size"
                                                                                                style="width: 30px;"&gt;
                                          &lt;label for="gift_no_{{ item.id }}"&gt;No&lt;/label&gt;&lt;input type="radio"
                                                                                              id="gift_no_{{ item.id }}"
                                                                                              onchange="hideShowGiftField(this.id, 'custom-message-{{ item.id }}')"
                                                                                              name="{{ item.variant.first.product.name }}_gift"
                                                                                              value="no"
                                                                                              class="mt-1 radio-size"
                                                                                              style="width: 30px;"&gt;
                                      &lt;/div&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
                              &lt;input type="hidden" id="custom-message-{{ item.id }}" class="placeholder"
                                     placeholder="Custom Message"
                                     name="custom_message_for_{{ item.id }}"
                                     style="width: 100%;"/&gt;
                              &lt;div class="row mt-3"&gt;
                                  &lt;div class="col-8"&gt;
  
                                      &lt;p style="font-size: 20px;"&gt;Need Engraving?&lt;/p&gt;
                                  &lt;/div&gt;
                                  &lt;div class="col-4"&gt;
                                      &lt;div class="d-flex" style="margin-left:15px ;"&gt;
                                          &lt;label for="engraving-yes"&gt;Yes&lt;/label&gt;&lt;input type="radio"
                                                                                       id="engraving_yes_{{ item.id }}"
                                                                                       onchange="hideShowEngravingField(this.id, 'engraving-message-{{ item.id }}')"
                                                                                       name="{{ item.variant.first.product.name }}_engraving"
                                                                                       value="yes"
                                                                                       class="mt-1 radio-size"
                                                                                       style="width: 30px;"&gt;
                                          &lt;label for="engraving-no"&gt;No&lt;/label&gt;&lt;input type="radio"
                                                                                     id="engraving_no{{ item.id }}"
                                                                                     onchange="hideShowEngravingField(this.id, 'engraving-message-{{ item.id }}')"
                                                                                     name="{{ item.variant.first.product.name }}_engraving"
                                                                                     value="no"
                                                                                     class="mt-1 radio-size"
                                                                                     style="width: 30px;"&gt;
                                      &lt;/div&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
                              &lt;input type="hidden" id="engraving-message-{{ item.id }}" class="placeholder"
                                     placeholder="Engraving Message"
                                     name="engraving_message_for_{{ item.id }}"
                                     style="width: 100%;"/&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                      &lt;!-- &lt;/td&gt; --&gt;
                      &lt;div class="col-4"&gt;
                          &lt;div class="row text-right"&gt;
                              &lt;div class="col-md-6 col-sm-12 mt-5"&gt;
                                  &lt;!-- &lt;td&gt; --&gt;
                                  &lt;div class="row d-flex justify-content-center counting"&gt;
                                      &lt;p class="mb-2 mx-3 font-weight-bold" id="cnt1"&gt;{{ item.quantity }}&lt;/p&gt;
                                      &lt;div class="d-flex flex-column plus-minus"&gt;
                                          &lt;form action="" method="post"&gt;
                                              {% csrf_token %}
                                              &lt;button onclick="increment('{% url 'item_increment' item.id %}')"
                                                      class="vsm-text plus"&gt;
                                                  +
                                              &lt;/button&gt;
                                          &lt;/form&gt;
                                          &lt;form action="" method="post"&gt;
                                              {% csrf_token %}
                                              &lt;button onclick="increment('{% url 'item_decrement' item.id %}')"
                                                      class="vsm-text minus"&gt;
                                                  -
                                              &lt;/button&gt;
                                          &lt;/form&gt;
                                      &lt;/div&gt;
                                  &lt;/div&gt;
                                  &lt;div class="button-remove" align="center"&gt;
                                      &lt;a href="{% url 'delete-cart-item' item.id %}" type="button"
                                         class="btn btn-danger remove-button mt-2"&gt;Remove
                                      &lt;/a&gt;
                                  &lt;/div&gt;
                              &lt;/div&gt;
                              &lt;div class="col-md-6 mt-2" align="center"&gt;
                                  &lt;h6 class="mob-text-price"&gt;Rs {{ item.get_subtotal }}&lt;/h6&gt;
                              &lt;/div&gt;
                          &lt;/div&gt;
                      &lt;/div&gt;
                  &lt;/div&gt;
                  &lt;hr&gt;
              {% endfor %}
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="container"&gt;
          &lt;div class="row total-price-desktop"&gt;
              &lt;div class="col-md-12"&gt;
                  &lt;div class="text-right total-price"&gt;Total : {{ total }}&lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
      &lt;div class="row total-price-mobile"&gt;
          &lt;div class="col-sm-12"&gt;
              &lt;div class="row"&gt;
                  &lt;div class="col-6"&gt;
                      &lt;div class="total" align="left"&gt;Total&lt;/div&gt;
                  &lt;/div&gt;
                  &lt;div class="col-6"&gt;
                      &lt;div class="price" align="right"&gt;Rs :{{ total }}&lt;/div&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/section&gt;
  &lt;hr&gt;
  &lt;section&gt;
      &lt;div class="container-fluid"&gt;
          &lt;div class="row mt-3"&gt;
              &lt;div class="col-4 offset-4"&gt;
                  &lt;div class="row d-flex justify-content-center"&gt;
                      {#                                &lt;input type="submit" value="Checkout"&gt;#}
                      &lt;button type="submit" class="btn btn-info" style="width: 50%"&gt;Checkout&lt;/button&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
              &lt;div class="text-checkout-bottom col-2 offset-2"&gt;
                  &lt;div style="float: right;"&gt;
                      &lt;p&gt;&lt;small&gt;*Shipping Calculated on Next Step&lt;/small&gt;&lt;/p&gt;
                      &lt;p style="margin-top: -20px;"&gt;&lt;small&gt;*Select gift wrapping on Next Step&lt;/small&gt;
                      &lt;/p&gt;
                  &lt;/div&gt;
              &lt;/div&gt;
          &lt;/div&gt;
      &lt;/div&gt;
  &lt;/section&gt;
  &lt;/form&gt;</code></pre>
  </div>
  </div>
  </p>