[Answered ]-Django auto-populate user in Createview

2👍

My python might be rusty, its been more than a year since I worked with Django.

As mentioned in the comments below by Daniel Roseman the request object is already available as a member on the view class.

You only need to grab the user from the request and feed that into the created instance before it is saved. This could be done in form_valid():

def form_valid(form):
    form.instance.match_join = self.request.user
    super(MatchCreate, self).form_valid(form)

Leave a comment