Могу ли я программно изменить в django хрустящие формы части помощника StrictButton? - PullRequest
0 голосов
/ 22 апреля 2020

Я вижу эту документацию:

https://django-crispy-forms.readthedocs.io/en/latest/crispy_tag_forms.html?highlight=change%20helper%20in%20view#manipulating -a-helper-in-a-view

и

https://django-crispy-forms.readthedocs.io/en/latest/dynamic_layouts.html

Я хочу изменить описание кнопки в представлении:

form.py

class GenericButtonForm(forms.Form):

    def __init__(self, *args, **kwargs):
        super(GenericButtonForm, self).__init__(*args, **kwargs)
        self.helper = FormHelper()
        self.helper.form_method = 'post'
        #self.helper.form_action = 'catalog:ave-properties'
        self.helper.form_class = 'form-inline'
        self.helper.field_template = 'bootstrap4/layout/inline_field.html'
        self.helper.layout = Layout(
            StrictButton('Id like to change this', type='submit', id='button-down-spinner', css_class='btn-info'),
        )

views.py

@login_required

def CheckAveView(request):
    template_name='catalog/check_AVE.html'

    if request.method == 'POST':
        GenericButtonForm_inst = GenericButtonForm()
        GenericButtonForm_inst.helper.form_action = reverse('catalog:ave-properties')
        # Can I change the butto descriprion? 'I'd like to change this'

        ave_props = check_AVE_query_json(sess)

    else:
        ave_props = ''
        GenericButtonForm_inst = GenericButtonForm()


    context = {
        'GenericButtonForm_inst': GenericButtonForm_inst,
        'ave_props': ave_props,
        }
    return render(request, template_name, context=context)

Можно ли манипулировать в представлении описанием кнопки?:

    self.helper.layout = Layout(
        StrictButton('Id like to change this', type='submit', id='button-down-spinner', css_class='btn-info'), 

Спасибо, Лука

...