Specifying default value for django hidden form field - bone DRY?
Posted
by
jMyles
on Stack Overflow
See other posts from Stack Overflow
or by jMyles
Published on 2010-12-14T05:43:12Z
Indexed on
2012/11/29
5:05 UTC
Read the original article
Hit count: 188
So let's say at the last minute (in the view) I decide I want to specify a default for a field and make it hidden, like so:
form.fields['coconut'] = forms.ModelChoiceField(label="", widget=forms.HiddenInput(), queryset=swallow.coconuts.all(), initial=some_particular_coconut)
My question is this: Do I really need to specify queryset here? I mean, I already know, from initial, exactly which coconut I'm talking about. Why do I also need to specify that the universe of available coconuts is the set of coconuts which this particular swallow carried (by the husk)?
Is there a way I can refrain from specifying queryset? Simply omitting causes django to raise TypeError.
If indeed it is required, isn't this a bit damp?
© Stack Overflow or respective owner