title: Django: request.user in form
body: <p>How may I get the user details to use within a from?  I know in the view I can just do:</p>
  
  <p><code>currentUser=request.user</code></p>
  
  <p>But if I use it in the form as so I get the following error "'request' is not defined".</p>
  
  <pre><code>class SelectTwoTeams(BootstrapForm):
  
      currentUser=request.user
  
      date_joined = currentUser.date_joined.replace(tzinfo=pytz.utc)
  
      timeless30 = datetime.datetime.now() - datetime.timedelta(seconds=3610)
      timeless30 = timeless30.replace(tzinfo=pytz.utc)
  
      if date_joined &gt; timeless30:
          currentCharities = forms.ModelChoiceField(queryset=Charity.objects.filter(enabled=1), empty_label=None, widget=forms.Select(attrs={"class":"select-format"}))
  
      team1 = forms.ModelChoiceField(queryset=StraightredTeam.objects.none(), empty_label=None,
                                 widget=forms.Select(attrs={"class":"select-format"}))
      team2 = forms.ModelChoiceField(queryset=StraightredTeam.objects.none(), empty_label=None,
                                 widget=forms.Select(attrs={"class":"select-format"}))
  </code></pre>
  
  <p>Many thanks for any help in advance.</p>
  
  <p>Below shows the <strong>init</strong> of this form just incase it may help.  I know how to get access to the user data using kwargs for this part:</p>
  
  <pre><code>def __init__(self, *args, **kwargs):
      user = kwargs.pop('user', None)
      self.currentSelectedTeam1 = kwargs.pop('currentSelectedTeam1', None)
      self.currentSelectedTeam2 = kwargs.pop('currentSelectedTeam2', None)
      self.currentfixturematchday = kwargs.pop('currentfixturematchday', None)
      self.currentCampaignNo = kwargs.pop('currentCampaignNo', None)
      super(SelectTwoTeams, self).__init__(*args, **kwargs)
  
      cantSelectTeams = UserSelection.objects.select_related().filter(~Q(fixtureid__fixturematchday=self.currentfixturematchday),campaignno=self.currentCampaignNo, )
  
      if not cantSelectTeams:
          queryset = StraightredTeam.objects.filter(currentteam = 1).order_by('teamname')
      else:
          queryset = StraightredTeam.objects.filter(currentteam = 1).exclude(teamid__in=cantSelectTeams.values_list('teamselectionid', flat=True)).order_by('teamname')
  
      teamsAlreadyPlaying = StraightredFixture.objects.filter(soccerseason=1025, fixturematchday=self.currentfixturematchday, fixturedate__lte = timezone.now())
      postponedGames = StraightredFixture.objects.filter(soccerseason=1025, fixturematchday=self.currentfixturematchday,fixturestatus = "P")
  
      queryset = queryset.exclude(teamid__in=teamsAlreadyPlaying.values_list('home_team_id', flat=True)).order_by('teamname')
      queryset = queryset.exclude(teamid__in=teamsAlreadyPlaying.values_list('away_team_id', flat=True)).order_by('teamname')
      queryset = queryset.exclude(teamid__in=postponedGames.values_list('home_team_id', flat=True)).order_by('teamname')
      queryset = queryset.exclude(teamid__in=postponedGames.values_list('away_team_id', flat=True)).order_by('teamname')
  
      self.fields['team1'].queryset = queryset
      self.fields['team2'].queryset = queryset
      self.fields['team1'].initial = self.currentSelectedTeam1
      self.fields['team2'].initial = self.currentSelectedTeam2
  
      self.fields['team1'].label = False
      self.fields['team2'].label = False
  
      date_joined = user.date_joined.replace(tzinfo=pytz.utc)
  
      timeless30 = datetime.datetime.now() - datetime.timedelta(seconds=3610)
      timeless30 = timeless30.replace(tzinfo=pytz.utc)
  
      if date_joined &gt; timeless30:
          self.fields['currentCharities'].label = False
  </code></pre>