I have the following view:
from django.views.generic.edit import CreateView
from news.forms import CreateNewsStoryForm
from news.models import NewsStory
class CreateNewsStoryView(CreateView):
model = NewsStory
form_class = CreateNewsStoryForm
All you need to know about the NewsStory
model, is that it has an author
foreign key field to User
. When a new NewsStory is created through the form, I want the new model's author
attribute to be set to the current user. How do I hook into the CreateView
's flow to set this up?
I'm certain it must be somewhere in the view, since the form doesn't have access to the request.
This seems like it would be a very common use case, but I can't seem to figure out the correct keywords to search for this, so excuse me if it has been asked before.