django - Using modelForm hidden field with Formsets without using Crispyform. -
i working forms sets, wondering how 1 use
<input type='hidden'
inside form set. (django formsets allow use multiple forms instances of single form)
its easy in normal single form put field type='hidden'
, name='fieldname
' e.g.
<input type='hidden' name='user' value='{{request.user.id}}'>
dealing formsets
bit catchy, how achieve same behavior forms sets?
views.py
pictureformset = modelformset_factory(picture, form=updatepictureform, extra=0) formset_qset = picture.objects.filter(id__in=[15, 16, 17, 18, 19, 20]) if request.method == post: ctx['form_set'] = pictureformset(request.post, queryset=formset_qset) ctx['form_set'].save() ctx['form_set'] = pictureformset(queryset=formset_qset) return render_to_response('temp tabs.html', context_instance=requestcontext(request, ctx))
template
<form method="post" action="" class="form-horizontal"> {% form in form_set %} {{form.id}} <div class="form-group"> <label class="col-lg-2 control-label"> {% form.meta_data.value|load_meta_data meta %} <div class="portfolio-item video-container"> <a class="" href="{% url 'view_image' form.id.value %}?in=pro"> <i style="background-image: url({{ meta.image_size.thumbnail_small }});" class="ds-thumbnail-container"></i> </a> </div> {% endwith %} </label> <div class="col-lg-8 "> {{ form.name }} </div> </div> {% endfor %} {{ form_set.management_form }} {% csrf_token %} <input type="submit" value="submit"> </form>
explanation
here in code, rendering images database editing there names. have url information inside meta_data
, have selected
fields=['id', 'meta_data', 'name']
we want change/update name, not meta_data
this code works fine part, how want keep 1 field unchanged modal?
i have meta_data
field using in template, not want field modified, value should in form this
{{form.meta_data}}
turns text area, different name , id. , expects changing. want declare hidden field , sets value form.meta_data.value
if have questions regarding please not hesitate ask. thanks.
Comments
Post a Comment