I was looking for solution for my problem here, but it didnt solve my problem.
I want to create user's profile while their signing up.
To signup I use CreateView
class UserRegisterView(generic.CreateView):
form_class = SignUpForm
template_name = 'registration/register.html'
success_url = reverse_lazy('login')
#this method doesn't work and I get
# `Profile.user" must be a "User" instance`
def form_valid(self,form):
Profile.objects.create(user=self.request.user)
My Profile model looks like:
class Profile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE)
#rest of fields like bio, social urls etc
My main point is to automatically create user's profile when their create their account. What is the best way to solve this?