title: How do I set user field in form to the currently logged in user?
body: <p>I'm making an election information app, and I want to allow the currently logged-in user to be able to declare himself <em>and only</em> himself as a candidate in an election.</p>
  
  <p>I'm using Django's built-in ModelForm and CreateView. My problem is that the Run for Office form (in other words, the 'create candidate' form) allows the user to select <em>any</em> user in the database to make a candidate. </p>
  
  <p>I want the user field in the Run for Office to be automatically set to the currently logged-in user, and for this value to be hidden, so the logged-in user cannot change the value of the field to someone else.</p>
  
  <p><strong>views.py</strong></p>
  
  <pre><code>class CandidateCreateView(CreateView):
      model = Candidate
      form_class = CandidateForm
      template_name = 'candidate_create.html'
  
      def form_valid(self, form):
          f = form.save(commit=False)
          f.save()
          return super(CandidateCreateView, self).form_valid(form)
  </code></pre>
  
  <p><strong>forms.py</strong></p>
  
  <pre><code>class CandidateForm(forms.ModelForm):
      class Meta:
          model = Candidate
  </code></pre>
  
  <p><strong>models.py</strong></p>
  
  <pre><code>class Candidate(models.Model):
      user = models.ForeignKey(UserProfile)
      office = models.ForeignKey(Office)
      election = models.ForeignKey(Election)
      description = models.TextField()
  
      def __unicode__(self):
          return unicode(self.user)
  
      def get_absolute_url(self):
          return reverse('candidate_detail', kwargs={'pk': str(self.id)})
  </code></pre>