'How to pass on django form results to a text box
I haven't been coding for more than a year now and am being a little rusty on some aspects. I have a django form designed using crispy_forms. Nothing very original : a bunch of radiobuttons, textbox...
Goal: My purpose is to have a generate_report button that once being clicked on open below the button a textbox with a text generated using the values picked for the former fields.
I created in models a __str__ method with the text I want. But I'm not sure that's the proper place for such a function.
I can have a text box hidden that only shows once someone click on the generate_report button using javascript, but I don't know how to pass on the text with the data. Any idea?
[forms.py]
from .models import Foo
from crispy_forms import bootstrap, helper, layout
class FooForm(forms.ModelForm):
class Meta:
model = Foo
fields = "__all__"
def __init__(self, request, *args, **kwargs):
self.request = request
super().__init__(*args, **kwargs)
actions = bootstrap.FormActions(layout.Submit("save", _("Save")),
bootstrap.StrictButton("generate_report", css_class="btn-success"))
self.helper = helper.FormHelper()
self.helper.form_action = self.request.path
self.helper.form_method = "POST"
self.helper.form_class = "blueForms"
self.helper.layout = layout.Layout(
field1,
field2,
field3,
actions
)
self.form_tag = False
self.render_required_fields = False
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|
