I am using django-crispy-forms along with bootstrap to render my django forms.
I want to use a file upload field like here, but I'm not sure how to get my html to output like this:
<div class="fileupload fileupload-new" data-provides="fileupload">
<div class="fileupload-new thumbnail" style="width: 50px; height: 50px;"><img src="http://www.placehold.it/50x50/EFEFEF/AAAAAA" /></div>
<div class="fileupload-preview fileupload-exists thumbnail" style="width: 50px; height: 50px;"></div>
<span class="btn btn-file"><span class="fileupload-new">Select image</span><span class="fileupload-exists">Change</span><input type="file" /></span>
<a href="#" class="btn fileupload-exists" data-dismiss="fileupload">Remove</a>
</div>
Using a ModelForm gives me an output like this:
<div id="div_id_my_id" class="control-group">
<label class="control-label " for="id_my_id"> My Model Field</label>
<div class="controls">
</div>
For a form like this:
class MyForm(ModelForm):
def __init__(self, *args, **kwargs):
super(MyForm, self).__init__(*args, **kwargs)
self.helper = FormHelper(self)
self.helper.layout = Layout(
Div(
Div('stuff', 'things' css_class='span6'),
Div('main_image', 'my_id', css_class='span6' ),
css_class='row-fluid'),
)
class Meta:
model=MyForm
So Im going to need to add a div, a span, and change some of their attributes. Have you faced this problem? Thanks for your ideas!