title: Get author(user) in Django
body: <p>I'm trying to make a news posting app using ModelForms, and currently I'm trying to set it so that the form automatically gets the authenticated user so when said user posts the news item, their name will appear, like "Posted By: User". In the models.py file, I've tried using: <code>models.ForeignKey(User)</code>, but it doesn't automatically set the user and it makes a drop-down widget appear in the form. It is not working correctly.</p>
  
  <p>How would I achieve what I'm trying to do, which is as stated earlier:</p>
  
  <ol>
  <li>Get the authenticated user who is posting the form</li>
  <li>Post his name on the page with the news item</li>
  </ol>
  
  <p>Posting code on request:</p>
  
  <p>Models.py:</p>
  
  <pre><code>from django.db import models
  from django.forms import ModelForm
  from django.contrib.auth.models import User
  
  # Create your models here.
  
  class NewsItem(models.Model):
      user = models.ForeignKey(User)
      date = models.DateField()
      news = models.TextField(max_length=100000)
  
      def __unicode__(self):
          return u'%s %s %s' % (self.user, self.date, self.news)
  
  class NewsForm(ModelForm):
      class Meta:
          model = NewsItem
  </code></pre>
  
  <p>Views.py:</p>
  
  <pre><code>from news.models import NewsForm
  from django.forms import forms
  from django.shortcuts import render
  from django.http import HttpResponseRedirect
  
  def news_poster(request):
      if request.method == 'POST':
          form = NewsForm(request.POST)
  
          if form.is_valid():
              form.save()
          return HttpResponseRedirect('/')
      else:
          form = NewsForm()
      return render(request,'news_post.html', {'form': form})
  </code></pre>
  
  <p>template:</p>
  
  <pre><code>{% extends "base.html" %}
  {% block title %}News poster {% endblock %}
  {% block content %}
      &lt;form action="/news/" method="POST"&gt;{% csrf_token %}
      {{ form.as_p}}
      &lt;input type="submit" value="Submit" /&gt;
      &lt;/form&gt;
  {% endblock %}
  </code></pre>