Reputation: 824
I want to render primary key id hidden input (<input type="hidden" name="form-0-id" value="5" id="id_form-0-id">
) directly in my template. I know I can render whole form, but I don't want to have any labels there. Is there some way to get it using the formset? I used object initial.id
, but it didn't work.
Method:
def getCellEditForm(self):
CellFormSet = modelformset_factory(Cell, extra=0, max_num=0)
form = CellFormSet(queryset=Cell.objects.filter(pk=self.id))
return form
Template:
{{ child.getCellEditForm.form.title }}
{{ child.getCellEditForm.form.parent }}
{{ child.getCellEditForm.form.initial.id }}
Upvotes: 1
Views: 3225
Reputation: 6284
{% for subform in formset.forms %}
{{ subform.id }}
{% endfor %}
or
{% for subform in formset.forms %}
<input type='hidden' id='id_form{{subform.id}}' name='form{{subform.id}}' value='{{subform.id}}' />
{% endfor %}
Upvotes: 1