title: Attaching a current User object to Django form
body: <p>I am working on an app that has a section with with a file upload form for .txt fiels.  I would like for the current user that is uploading the file to be added along with the file and the file name.  Currently, I can do this successfully in the admin section but I just cant get it to save via the form itself.  Any Ideas?</p>
  
  <p>Here are the models:</p>
  
  <pre><code>class UploadedTextFile(models.Model):
  file = models.FileField(upload_to="textfiles")
  filename = models.CharField(max_length = 50)
  username = models.ForeignKey(User, blank=True, null=True)
  
  
  class UploadedTextFileForm(ModelForm):
      class Meta:
          model = UploadedTextFile
          fields = ['file', 'filename']
  </code></pre>
  
  <p>Here is my view:</p>
  
  <pre><code>def inputtest(request):
  
  #response for file being submited
      if request.method == "POST":
          form = UploadedTextFileForm(request.POST)  
          if form.is_valid():
              new_form = form.save(commit=False)
              new_form.username = request.user
              new_form.save()
  
  
          return render(request, 'about.html')
  
      inputtest = UploadedTextFileForm()
      return render(request, 'failed.html', {'inputtest': inputtest})
  
      else:
          inputtest = UploadedTextFileForm()
          return render(request, 'inputtest.html', {'inputtest': inputtest})
  </code></pre>
  
  <p>Here is my html:</p>
  
  <pre><code>{% extends 'base.html' %}
  
  {% block content %}
  &lt;form method="post"&gt;{% csrf_token %}
  {{ inputtest.as_p }}
  &lt;input type="submit" value="Submit" /&gt;
  &lt;/form&gt;
  
  {% endblock content %}
  </code></pre>