Django crispy-forms, BaseGenericInlineFormSet & allow_delete

*爱你&永不变心* 提交于 2019-12-19 02:05:21

问题


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!


回答1:


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',
    )


来源:https://stackoverflow.com/questions/12446744/django-crispy-forms-basegenericinlineformset-allow-delete

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!