Django crispy-forms,BaseGenericInlineFormSet& allow_delete [英] Django crispy-forms, BaseGenericInlineFormSet & allow_delete

查看:129
本文介绍了Django crispy-forms,BaseGenericInlineFormSet& allow_delete的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到一个问题,同时使用django-crispy形式,我无法得到答案。
我有一个相当复杂的表单布局,迄今为止,一切工作都非常好用cripy-forms。



表单的一部分使用通用的内联表单集。这也是有效的,但我的问题是,我无法弄清楚如何访问delete-checkbox(当有 can_delete = True



相应的代码看起来像:

  class BaseReleaseReleationFormSet(BaseGenericInlineFormSet):

def __init __

self.instance = kwargs ['instance']
super(BaseReleaseReleationFormSet,self).__ init __(* args,** kwargs)

self.helper = FormHelper()
self.helper.form_id =id_relation_form
self.helper.form_class ='form-horizo​​ntal'
self.helper.form_method ='post'
self.helper.form_action =''
self.helper.form_tag = False

base_layout =行(
列(
字段('name',css_class ='input-small'),
#Field('delete',css_class ='input -
css_class ='span3'
列(
Field('url',css_class ='input-xlarge'),
css_class ='span4'
),
css_class ='row relation-row',


self.helper.add_layout(base_layout)

名称和网址字段根据需要以脆皮形式呈现,但删除复选框将显示在表单的末尾。我无法在布局中访问它。



有人知道如何解决这个问题吗?任何提示?感谢提前!

解决方案

愚蠢的我 - 想出来..删除字段被称为删除。 (注意大写字母...)

  base_layout =行(
列(
Field名称',css_class ='input-small'),
css_class ='span3'
),
列(
Field('url',css_class ='input-xlarge' )
Field('DELETE',css_class ='input-small'),
css_class ='span4'
),
css_class ='row relation-row',


I came across a question while working with django-crispy-forms for which I'm unable to get an answer. I have a rather complex form layout, everything works extremly nice with cripy-forms so far.

One part of the form uses a generic inline formset. This is working as well, but my problem is, that i cannot figure out how to access the delete-checkbox (when having can_delete=True)

The corresponding code looks something like:

class BaseReleaseReleationFormSet(BaseGenericInlineFormSet): 

    def __init__(self, *args, **kwargs):

        self.instance = kwargs['instance']
        super(BaseReleaseReleationFormSet, self).__init__(*args, **kwargs)

        self.helper = FormHelper()
        self.helper.form_id = "id_relation_form"
        self.helper.form_class = 'form-horizontal'
        self.helper.form_method = 'post'
        self.helper.form_action = ''
        self.helper.form_tag = False

        base_layout = Row(
                Column(
                       Field('name', css_class='input-small'),
                       #Field('delete', css_class='input-small'),
                       css_class='span3'
                       ),
                Column(
                       Field('url', css_class='input-xlarge'),
                       css_class='span4'
                       ),
                css_class='row relation-row',
        )

        self.helper.add_layout(base_layout)

The name and url field are rendered with crispy-forms as desired, but the delete-checkbox appears at the end of the form. And I'm unable to access it in the layout.

Does someone know how to address this problem? Any tips? Thanks in advance!

解决方案

Stupid me - figured it out.. The delete field is referenced as "DELETE". (note the capital letters...)

    base_layout = Row(
            Column(
                   Field('name', css_class='input-small'),
                   css_class='span3'
                   ),
            Column(
                   Field('url', css_class='input-xlarge'),
                   Field('DELETE', css_class='input-small'),
                   css_class='span4'
                   ),
            css_class='row relation-row',
    )

这篇关于Django crispy-forms,BaseGenericInlineFormSet& allow_delete的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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