My question is very similar to this question: http://stackoverflow.com/questions/862522/django-populate-user-id-when-saving-a-model
Unfortunately I did not quite understand their answer.
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.
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})
Everytime I submit my form it mentions:
null value in column "user_id" violates not-null constraint
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?