使用django_tables2和django fm模态形式时如何解决记录的删除过程

时间:2019-04-01 09:51:37

标签: django django-forms django-tables2

我的问题是,使用django_tables2和fm模态形式时,无法成功删除类的对象。

编辑操作有效,但是删除操作无法正常进行,因为按下删除按钮后,应用程序将重定向到同一端点,而没有删除对象。

通知:我在表中添加了ProductSerialNumbers类的编辑和删除字段。py

这里有什么我想念的吗?

urls.py

url(r'^warehouse_stuffing/edit/(?P<pk>\d+)/$', views.ProductSerialNumbersUpdateView.as_view(), name='warehouse_stuffing_update'),

url(r'^warehouse_stuffing/delete/(?P<pk>\d+)/$', views.ProductSerialNumbersDeleteView.as_view(), name='warehouse_stuffing_delete'),

tables.py

class ProductSerialNumbersTable(tables.Table):
    #add new columns(edit,delete)

    edit=tables.LinkColumn('warehouse_stuffing_update',args=[A('pk')],accessor='Edit',orderable=False,empty_values=())

    delete=tables.LinkColumn('warehouse_stuffing_delete',args=[A('pk')],accessor='Delete',orderable=False,empty_values=())


    class Meta:
        #define the model
        model = ProductSerialNumbers
        template_name = 'django_tables2/bootstrap.html'


    def render_delete(self,record):
        #create the link with modal form for delete
        return format_html('<a href="/warehouse_stuffing/delete/{}/" class="fm-delete" data-fm-head="Delete of Serial Number" data-fm-callback="redirect" data-fm-target="/psn/"><button class="btn btn-danger btn-sm" type="">Delete</button></a>',record.id)


    def render_edit(self,record):
        #create the link with modal form for edit
        return format_html('<a href="/warehouse_stuffing/edit/{}/" class="fm-update" data-fm-head="Edit of Serial Number" data-fm-callback="reload"><button class="btn btn-primary btn-sm" type="">edit</button></a>',record.id)

views.py

def psn(request):
    #psns stands for prodct serial numbers 's
    psns=ProductSerialNumbers.objects.all()

    table = ProductSerialNumbersTable(psns)
    RequestConfig(request).configure(table)
    return render(request, 'warehouse/simple_list.html', {'table': table})

0 个答案:

没有答案