title: Django: Save User ID with Model Save
body: <p>My question is very similar to this question:  <a href="https://stackoverflow.com/questions/862522/django-populate-user-id-when-saving-a-model">Django: Populate user ID when saving a model</a></p>
  
  <p>Unfortunately I did not quite understand their answer.</p>
  
  <p>When a user logs in I want them to be able to submit a link and I have a user_id foreign key that I just can't seem to get to populate.</p>
  
  <pre><code>def submit(request):
      if request.method == 'POST':
          form = AddLink(request.POST)
          if form.is_valid():
              form.save()
              return redirect('home')
      else:
          form = AddLink()
  
      return render_to_response('links/submit.html', {'form': form})
  </code></pre>
  
  <p>Everytime I submit my form it mentions:</p>
  
  <pre><code>null value in column "user_id" violates not-null constraint
  </code></pre>
  
  <p>Which I understand but what I don't know how to add user_id to the my form object.  How can I access the currently logged in user's id and submit it along with my form data?</p>