I have a problem with the initial value of a hidden field in a modelform deployed in a formset. Just the first form have the initial value in the hidden field and the others are empty.
The modelForm is:
class md_changelogFormModel(forms.ModelForm):
post_docs = forms.CharField(widget=forms.HiddenInput(),
initial="READY_FOR_RUN")
# Other fields
class Meta:
model = md_changelog
fields = '__all__'
The same model md_changelog is used in a form based in BaseInlineFormSet:
class md_changelogForm(BaseInlineFormSet)
class Meta:
model = md_changelog
fields = '__all__'
And a formset class is created with inlineformset_factory:
md_changelogFormSet = inlineformset_factory(md_orderlog, md_changelog,
form=md_changelogFormModel,
formset=md_changelogForm,
extra=1, max_num=20)
And the formset class is instantiated in a class based view:
def get(self, request, *args, **kwargs):
"""
Handles GET requests and instantiates blank versions of the form
and its inline formsets.
"""
self.object = None
form_class = self.get_form_class()
form = self.get_form(form_class)
md_changelog_form = md_changelogFormSet(initial=[{'post_docs':'READY_FOR_RUN'}])
return self.render_to_response(
self.get_context_data(form=form,
md_changelog_form=md_changelog_form))
The problem is that when the post function receives the request.POST, only the post_docs hidden field in the first form of the formset data is filled with the initial value, the others no.
How can I initialize the other forms?
Thanks!