删除链接不会与django-dynamic-formset一起使用的Django Formsets显示 [英] Delete links are not displayed for Django Formsets used together with django-dynamic-formset

查看:304
本文介绍了删除链接不会与django-dynamic-formset一起使用的Django Formsets显示的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在关注教程,该教程显示如何在Django中使用Formsets。本教程使用django-dynamic-formset JQuery插件,它可以在Django管理中启用formets的版本。

I am following this tutorial which shows how to work with Formsets in Django. The tutorial uses django-dynamic-formset JQuery plugin which enables edition of formsets as in Django admin.

假设我有以下形式:

<form  enctype="multipart/form-data" method="post">
   {% csrf_token %}

       {% for place_form in places_formset %}
            <div class="place_formset">
                <div class="required field">
                  <label>{{ place_form.name.label }}</label>
                  <div class="ui icon input">
                    {{ place_form.name }}
                  </div>
                </div>
            </div>
        {% endfor %}

       {{ places_formset.management_form }}

    <br>
    <button  type="submit">Save changes</button>

当我呈现表单时,我收到添加项目链接,允许我添加另一个表单到formset(也意味着js和jQuery被加载和工作),但是我看不到应该删除每个表单实例的链接。

When I render the form I get "Add item" link which allows me to add another form to the formset.(means also that js and JQuery is loaded and working) but I don't see links which should remove each form instance.

这里有关于从内联表单中删除项目的说明,但没有任何说明关于常规表单。

Here there is explanation about deletion of items from inline formsets but nothing is said about regular formsets.

我迄今为止所做的一切:

What I have done so far:

1.我尝试包括:

   {{ place_form.DELETE }}

进入形式,认为django-dynamic-formset将用删除链接替换所有渲染的复选框,但没有发生。

into the form thinking that django-dynamic-formset will replace all the rendered checkboxes with "remove" links but it didn't happen.

2。另外,我已经尝试使用显式的can_delete渲染集类,但是没有解决问题:

2.Also I have tried to render set class with explicit can_delete but it didn't solve the problem:

  PlaceFormSet = formset_factory(PlaceForm, can_delete=True)

3.不用按字段渲染表单字段我已经尝试渲染{{places_formset}}。在这种情况下,窗体呈现删除复选框,但没有替换为删除链接。另外添加项目链接已经消失了。

3.Instead of rendering the form field by field I have tried to render it with {{ places_formset }}. In this case the form renders with delete checkboxes, but there are not replaced with remove links. Also add item link has disappeared.

我还能做些什么来启用删除链接?

What else can I do to enable remove links?

推荐答案

Django-dynamic-formset对我来说不能正常工作。查看代码后,我已经显式地显示了链接:

Django-dynamic-formset is not working correctly for me. After looking in its code I have rendered the links explicitly:

<a href="javascript:void(0)" class="delete-row">{% trans 'delete' %}</a>

这篇关于删除链接不会与django-dynamic-formset一起使用的Django Formsets显示的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆