i have a modelform like so:
class CommentForm(forms.ModelForm):
storyId = forms.IntegerField(required=True, widget=forms.HiddenInput())
postId = forms.IntegerField(required=True, widget=forms.HiddenInput())
so now i want to change the value of the "storyId"
i've found that, in my code i need to do this:
form = CommentForm()
form.initial['storyId'] = xyz
or in the init of the model i need this:
self.initial['storyId'] = xyz
what is the "initial" doing? Why cannot i just go straight to:
form = CommentForm()
form.storyId = xyz
thanks!
UPDATE if i run form.storyId = xyz, then in the template, I will not see the value passed in. If i run
form.initial['storyId'] = xyz
then in the template i do see the values passed in! No other code changes, any ideas?
initialas parameter when you create your formform = CommentForm(initial={'storyId':xyz})