1👍
You’re missing a step here. You need to check that both the user and the profile forms are valid. Then, you need to save the user form to get a User object. Then you need to create the profile object, associate it with the user, and save it.
I don’t know why you’re setting the profile picture separately – surely it should be part of the Profile form, and will be saved alongside it.
0👍
Here’s where I think you’re getting confused:
userForm = SignupForm(request.POST, instance=user)
profileForm = ProfileForm(request.POST, request.FILES)
You’re using two different forms at the same time, but only validating the first:
if userForm.is_valid():
And what you’re getting is a User has no profile.
because, while the user exists, the profile does not (not before running the profileForm.save()
anyway). Remember, those are two different models. And even then, you’re also doing it wrong for two reasons:
- picture will reside in
request.FILES
and notrequest.POST
because it is, well, a file - you’re trying to assign the picture to
user.profile.picture
– but that makes no sense, because you should assign it to the profile and then link that profile to the user (remember, user is a field on the Profile model). And of course, if picture is part of the form you don’t need to do this anyway
So, essentially, this:
profileForm = ProfileForm(request.POST, request.FILES)
profileForm.instance.user = request.user #link the profile to current user
if profileForm.is_valid():
profileForm.save() #now you have a profile
- [Answer]-Ng-route does not make template requests
- [Answer]-How to export a schedule to Google Calendar?
- [Answer]-Tastypie – Should method be in UserResource or ThreadResource?
- [Answer]-Multiple joins in Django model
- [Answer]-Django admin list view customizable by user