Django Form - Passing Values
<p>I have the following form and can't seem to use the "self.currentSelectedTeam1" as the initial value for team1 as can be seen at the bottom.  When I do try this I get the following error:</p>

<pre><code>team1 = forms.ModelChoiceField(queryset=StraightredTeam.objects.none(), empty_label=None,initial=self.curentSelectedTeam1)
NameError: name 'self' is not defined
</code></pre>

<p>Form:</p>

<pre><code>class SelectTwoTeams(BootstrapForm):

    def __init__(self, *args, **kwargs):
        user = kwargs.pop('user', None)
        self.curentSelectedTeam1 = kwargs.pop('curentSelectedTeam1', None)
        self.curentSelectedTeam2 = kwargs.pop('curentSelectedTeam2', None)
        super(SelectTwoTeams, self).__init__(*args, **kwargs)
        queryset = StraightredTeam.objects.filter(currentteam = 1)

        self.fields['team1'].queryset = queryset
        self.fields['team2'].queryset = queryset

    team1 = forms.ModelChoiceField(queryset=StraightredTeam.objects.none(), empty_label=None,initial=self.curentSelectedTeam1)
    team2 = forms.ModelChoiceField(queryset=StraightredTeam.objects.none(), empty_label=None,initial=self.curentSelectedTeam2)
</code></pre>

<p>Many thanks in advance for any help, Alan.</p>

<p>The problem is in <code>self</code> keyword in team1 and team2 variables. 
The thing is they are on the class-level, and the self is available on the instance level(inside methods, excluding static methods and class methods)</p>

<p>To make it work you need to do the same with <code>self.fields['team1'].queryset</code>:</p>

<pre><code>self.fields['team1'].initial = self.curentSelectedTeam1
</code></pre>

<p>inside <code>__init__</code> method.</p>

python django