使用django-popup-view-field创建一个用于确认删除操作的弹出窗口

时间:2017-06-02 00:01:46

标签: python django popup

我尝试使用django-popup-view-field创建一个用于确认删除操作的弹出窗口。我一直在关注https://pydigger.com/pypi/django-popup-view-field中给出的例子。我面临的挑战是当我点击drivers_list.html中的删除按钮时,为我要删除的用户传递主键。这是我的代码:`

drivers_list.html

{% for driver in object_list %}
   <tr>
       <td>{{ driver.first_name }} </td>
       <td>{{ driver.last_name }}</td>
       <td>{{ driver.licence_category }}</td>
       <td>{{ driver.phone }}</td>
       <td>{{ driver.email }}</td>
       <td>{{ driver.status }}</td>
       <td align="center">
           <a href="{% url 'view_driver' pk=driver.id %}"><button class="btn btn-success btn-sm">View</button></a>
           <a href="{% url 'edit_driver' pk=driver.id %}"><button class="btn btn-primary btn-sm">Edit</button></a>
           <a href="{% url "django_popup_view_field:get_popup_view" 'delete_driver' pk=driver.id %}"><button class="btn btn-danger btn-sm">Delete</button></a>
       </td>
   </tr>
{% endfor %}

** driver_confirm_delete.html **

<h4><span class="label label-warning">Are you sure you want to delete {{ driver.first_name }} {{ driver.last_name }}?</span></h4>
<div class="row">
    <div class="col-md-4">
        <form action="{{ target }}" method='POST'>
            {% csrf_token %}
            <h4><span class="label label-warning">NOTE:This action cannot be reversed!</span></h4>
            <ul>
                {{ form.as_ul }}
            </ul>
            <input type="submit" class="btn btn-danger btn-md" value="Confirm delete"/>
            <a href="{% url 'drivers_list' %}"><button type="button" class="btn btn-info btn-md">Cancel</button></a>
       </form>
    </div>
</div>

urls.py

urlpatterns = [
url(r'^delete_driver/(?P<pk>\d+)/$', d_views.DeleteDriverView.as_view(), name='delete_driver'),
url(r'^django_popup_view_field/', include('django_popup_view_field.urls', namespace="django_popup_view_field")),]

views.py

class DeleteDriverView(FormMessagesMixin, DeleteView):

    model = Driver
    template_name = 'drivers/driver_confirm_delete.html'
    success_url = reverse_lazy('drivers_list')
    form_valid_message = 'Driver was deleted successfully!'

1 个答案:

答案 0 :(得分:0)

让我创建一个表格:

cv::Mat img(frame->height,frame->width,CV_8UC1,frame->data[0]); 
imwrite( "pic.jpg", img );

在JS中:

  <thead>
       <tr>
         <th>#</th>
         <th>Name</th>
         ...
         <th>Delete</th>
       </tr>
  </thead>

    {% for driver in object_list %}
   <tr>
       <td>{{ driver.first_name }} </td>
       <td>{{ driver.last_name }}</td>
       <td>{{ driver.licence_category }}</td>
       <td>{{ driver.phone }}</td>
       <td>{{ driver.email }}</td>
       <td>{{ driver.status }}</td>
       <td class="delete"value={{driver.id}}><i class="fa fa-remove w3-text-red"></i></td>
   </tr>
   {% endfor %}