DEV Community

Discussion on: Create Advanced User Sign Up View in Django | Step-by-Step

 
supergoogler profile image
SuperGoogler

Not working, and the strangest part is that the registration, and login is getting successful. The data is going to the database for User model, but now the data has stopped going for the "UserProfile" model to the DB. Before, though the data was not showing up on the web page but the data was going the DB. Below is the ORM query output

User.objects.all()
, , , , , ]>

UserProfile.objects.all()


I really appreciate your effort, and hope we rectify the issue soon. If you are comfortable, I can share my project as a compressed file with you if you would like to test in your environment.
Below is what I see on the web page:

email: email@gmail.com
fname: sam
lname: Sahay
DOB:
Country:
State:
District:

As you could see, first three fields are populating data, but rest not.

Amitesh

Thread Thread
 
supergoogler profile image
SuperGoogler

Please disregard the previous reply. My apologies. The data is showing up in the database for User model as well as the UserProfile model. I will keep you posted over the latest suggestion by you. There is some issues with the routes . I need to fix that before I see the profile page.

Thank you again.
Amitesh

Thread Thread
 
supergoogler profile image
SuperGoogler

Hi,

Ok, so there has been some progress. I followed you instructions as well as I modified the function that is responsible to let the authenticated users fill in the form. Below are the two functions that is now modified.

def userprofileview(request): # Authenticated user filling the form to complete the registration
if request.method == 'POST':
form = UserProfileForm(request.POST, request.FILES)
if form.is_valid():
pr = UserProfile()
pr.user = User.objects.get(id=request.user.id)
# pr.first_name = form.cleaned_data['first_name']
# pr.last_name = form.cleaned_data['last_name']
# pr.email = form.cleaned_data['email']
pr.dob = form.cleaned_data['dob']
pr.country = form.cleaned_data['country']
pr.State = form.cleaned_data['State']
pr.District = form.cleaned_data['District']
pr.phone = form.cleaned_data['phone']
pr.save()
messages.success(request, f'Profile has been updated successfully')
return redirect('/profile')
else:
messages.error(request, AssertionError)
else:
form = UserProfileForm()
return render(request, 'authenticate\bolo.html', context={'form': form})

@login_required
def profile_page(request): # Fetching data from DB to show user's complete profile page
data = get_object_or_404(UserProfile, user=request.user)
print('data=', data)
context = {'data': data}
return render(request, 'authenticate\profile.html', context)

1)As you could see in the "userprofileview" view, I have used the form.cleaned_data[] for all the form fields.

2) In the "profile_page", I have used your suggestion.

The change in the webpage is that, now I could see data for all the fields from the custom model UserProfile. However, now the fname, lname, and email is not populating the data.

email:
fname:
lname:
DOB:May 4, 2020
Country: India
State: Mahrashtra
District: Pune

So, I tried the form.cleaned_data() over the first_name, last_name and email. However, it didn't work.
Please suggest,

Thank you
amitesh