I want to use CreateView along with crispy-forms generated layout. However, it seems that everything I pass to self.helper in forms.py is ignored. Form renders nicely, but only with fields generated by CreateView - all fields passed to Layout are missing.
My views.py
class MyView(CreateView):
form_class = MyForm
model = MyModel
def form_valid(self, form):
pass
My forms.py:
from django.forms import ModelForm, Textarea
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Submit, Layout
from crispy_forms.bootstrap import FormActions
from .models import MyModel
class MyForm(ModelForm):
def __init__(self, *args, **kwargs):
super(MyForm, self).__init__(*args, **kwargs)
self.helper = FormHelper(self)
self.helper.form_method = 'POST'
self.helper.add_input(Submit('submit', 'Submit'))
self.helper.layout = Layout(
FormActions(Submit('BlahBlah', 'BlahBlah', css_class='btn-primary')))
class Meta:
model = MyModel
fields = ['xxx', 'yyy']
My image_form.html:
{% load crispy_forms_tags %}
...
<form action="" method="post" enctype="multipart/form-data">
{% csrf_token %}
{{ form|crispy }}
</form>
What else should I do to make it work?