what is the easiest way to set a default choice for a django select widget?

I have a model that has a foreign key relation to another. I'd like to have the dropdown that is produced by widget=forms.Select have a default value

13.10.2009 18:15:57
1 ОТВЕТ
РЕШЕНИЕ

Maybe just create a form and set the field's initial value:

class SomeForm(forms.ModelForm):

    class Meta:
        model = SomeModel
        fields = ('field',)

    def __init__(self, *args, **kwargs):
        super(SomeForm, self).__init__(*args, **kwargs)
        self.fields['field'].initial = 'initial value'
3
3.06.2016 14:01:07