title: deleting multiple rows using check boxes with jquery in django?
body: <hr>
  
  <p>deleting multiple rows using check boxes with jquery in django???</p>
  
  <hr>
  
  <pre><code>def lead_delete(request, id):
      success_dict = {}
      task_del =Lead.objects.filter(id=id)
  
      if request.method== "GET":
          task_del.delete()
  
          success_dict['success_msg'] = "Successfully Deleted lead"
          return redirect('sales_manager_dashboard')  
  </code></pre>
  
  <hr>
  
  <pre><code>url(r'^lead/delete/(?P&lt;id&gt;\d+)/$','lead_delete',name='lead_delete'),
  </code></pre>
  
  <hr>
  
  <pre><code>&lt;div class="panel panel-default"&gt;
      &lt;div class="panel-heading"&gt;
          {% if request.user|has_group:"sales rep" or request.user|has_group:"sales manager" %}
              &lt;div class="col-md-11"&gt;
              &lt;h4&gt;Leads/Enquiries&lt;/h4&gt;
              &lt;/div&gt;
             &lt;!--  &lt;button type="button"   class="btn btn-primary" data-toggle="modal" data-url="{% url 'ImportWorkItem' %}" data-title="CSV Import" data-target=".bs-example-modal-lg" style="color: "&gt;CSV&lt;/button&gt; --&gt;
  
  
              &lt;button type="button"  class="btn btn-primary" data-toggle="modal" data-url="{% url 'export_leads_form' %}" data-list-div-url="{% url 'export_leads_form' %}" data-title="Add Enquiry" data-target=".bs-example-modal-lg"&gt;Export&lt;/button&gt;
  
              &lt;button type="button" class="btn btn-primary" data-toggle="modal" data-url="{% url 'lead_add' %}" data-list-div-url="{% url 'leads_list' %}" data-title="Add Enquiry" data-target=".bs-example-modal-lg"&gt;New&lt;/button&gt;
  
  
          {% else %}
              &lt;div class="col-md-11"&gt;
              &lt;h4&gt;Leads/Enquiries&lt;/h4&gt;
              &lt;/div&gt; 
              &lt;button type="button"  class="btn btn-primary" data-toggle="modal" data-url="{% url 'export_leads_form' %}" data-list-div-url="{% url 'export_leads_form' %}" data-title="Add Enquiry" data-target=".bs-example-modal-lg"&gt;Export&lt;/button&gt;
  
          {% endif %}
      &lt;/div&gt;
  
      &lt;div class="panel-body " style="overflow:scroll"&gt;
       &lt;form&gt;
          &lt;table id="lead_list_table" class="table table-bordered hover" data-url="{% url 'leads_list' %}" cellspacing="0" width="100%"&gt;
              &lt;thead&gt;
                  &lt;tr class="headings"&gt;
                      &lt;th&gt;&lt;input type="checkbox" id="selectall"/&gt;&lt;/th&gt;
                      &lt;th&gt;Company&lt;/th&gt;
                      &lt;th&gt;Contact Person&lt;/th&gt;
                      &lt;th&gt;Email&lt;/th&gt;
                      &lt;th&gt;Phone&lt;/th&gt;
                      &lt;th&gt;Country&lt;/th&gt;
                      &lt;th&gt;Lead Date&lt;/th&gt;
                      &lt;th&gt;Next Followup&lt;/th&gt;
                      &lt;th&gt;Lead Status&lt;/th&gt;
  
                      &lt;th class="no-link last"&gt;&lt;span class="nobr"&gt;&lt;/span&gt;
                      &lt;/th&gt;
                  &lt;/tr&gt;
              &lt;/thead&gt;
              &lt;tbody&gt;
                  {% for lead in leads %}
                      &lt;tr class=""&gt;
                          &lt;td class=""&gt;&lt;input type="checkbox" class="checkbxcolor" id="lead"&gt;&lt;/td&gt;
                          &lt;td class=" "&gt;&lt;a  data-url="{% url 'leads_view' lead.id%}" id="lead" data-toggle="modal" data-title="View Enquiry" data-target=".bs-example-modal-lg"&gt;{{ lead.title }}&lt;/a&gt;&lt;/td&gt;
                          &lt;td class=" "&gt;{{ lead.contact_name }} &lt;/td&gt;
                          &lt;td class=" "&gt;{{ lead.email }}&lt;/td&gt;
                          &lt;td class=" "&gt;{{ lead.phone }}&lt;/td&gt;
                          &lt;td class=" "&gt;{{ lead.country }}&lt;/td&gt;
                          &lt;td &gt;{{ lead.lead_date}}&lt;/td&gt;
                          &lt;td class=""&gt;{{lead.latest_followup_date}}&lt;/td&gt;
                          &lt;td style="text-align: center;padding: 10px;"&gt;{{ lead.latest_lead_status}}
                          &lt;td class="last"&gt;
  
                              {% if request.user|has_group:"sales rep" or request.user|has_group:"sales manager" %}
                                  &lt;button type="button" class="btn btn-secondary" data-toggle="modal" data-url="{% url 'lead_edit' lead.id %}"data-list-div="lead_list_div" data-list-div-url="{% url 'leads_list' %}" data-title="Edit Enquiry" data-target=".bs-example-modal-lg"&gt;Edit&lt;/button&gt;
                              {% endif %}           
                             &lt;a href="{% url 'lead_delete' id=lead.id %}"&lt;button type="delete_button" id="remove" class="btn btn-danger remove"  &gt;Delete &lt;/button&gt;&lt;/a&gt;
  
                          &lt;/td&gt;
                      &lt;/tr&gt;
  
                  {% endfor %}
              &lt;/tbody&gt;
              &lt;tfoot&gt;
                  &lt;tr&gt;
                      &lt;th colspan="6"&gt;&lt;a href="javascript:;" class="deleteall"  title="dtable" &gt;Delete Selected&lt;/a&gt;
  
                      &lt;/th&gt;
                  &lt;/tr&gt;
              &lt;/tfoot&gt;
          &lt;/table&gt;
      &lt;/form&gt;   
      &lt;/div&gt;
  
  &lt;/div&gt;
  
  &lt;script type="text/javascript"&gt;
  
      $(document).ready( function () {
              $('#lead_list_table').DataTable({
                  "responsive": true,
                  "bFilter": false,
                  "searching": true,
                  "ordering": false,
  
  
                  "fnRowCallback": function( nRow, aData, iDisplayIndex, iDisplayIndexFull ) {
                      if(aData[7] == "PROSPECTING")
                      {
                          $('td:eq(7)', nRow).css('background-color', 'rgb(129,164,216, 0.90)');
                      }
                      else if(aData[7] == "TRIAL")
                      {
                          $('td:eq(7)', nRow).css('background-color', 'rgb(0,128,0, 0.58)');
                      }
                      else if(aData[7] == "NEGOTIATING")
                      {
                          $('td:eq(7)', nRow).css('background-color', 'rgb(243,156,18,0.6)');
                      }
                      else if(aData[7] == "WON")
                      {
                          $('td:eq(7)', nRow).css('background-color', 'rgb(0,250,154)');
                      }
                      else if(aData[7] == "LOST")
                      {
                          $('td:eq(7)', nRow).css('background-color', 'rgb(250,128,114');
                      }
  
                  }
              });
  
  
  });
  
  &lt;/script&gt;
  
  
  
  &lt;script type="text/javascript"&gt;
  
      $(document).ready(function () {
  
          $("#selectall").click(function () {
                $('.case').attr('checked', this.checked);
          });
  
          $('a.deleteall').on('click', function(e){
              e.preventDefault();
              var $this = $(this), 
                  $trows = $this.closest('table').children('tbody').find('tr.selected'),
                  sel = !!$trows.length;
  
              // Don't confirm delete if no rows selected.
              if(!sel){
                  alert('No rows selected');
                  return false;
              }
              var c = confirm('Are you sure you want to delete the slected rows?');
              if(!c) { return false; }
              $trows.fadeOut(function(){
               $trows.remove();
           });
  
        });
   });
  
  
  &lt;/script&gt;
  </code></pre>
  
  <hr>