[Fixed]-How to automatically set foreign key in django create view

1👍

Try adding the following inside the form_valid method.

def form_valid(self, form):
    # ...
    profile = Profile.objects.get(user=self.request.user) # or something similar 
    form.instance.profile = profile
    # return the super as you do
👤NS0

Leave a comment