Skip to content Skip to sidebar Skip to footer

Registration Form Not Saving Data In Profile Model, Using Extended Django User Model

Recently i am facing a problem in registration. I have made a ** accounts** app in my project for registrations. I don't want to save data in default **User** model in dB. So I hav

Solution 1:

May be try referencing the profile model from the user since it's a one to one field

from django.shortcuts import render
from django.http import HttpResponse, JsonResponse
# Create your views here.
from .forms import ProfileForm,InfoProfileForm
from django.http.response import HttpResponse

def registration(request):
    if request.method == 'POST':
        profile_form = ProfileForm(request.POST)
        info_form = InfoProfileForm(request.POST)

        if profile_form.is_valid() and info_form.is_valid():
            user = profile_form.save(commit=True)
            user.set_password(user.password)
            user.profile.phone = user.cleaned_data["phone"]
            user.profile.address = user.cleaned_data["address"]
            user.save()

            print('submitted')
        else:
            HttpResponse("<h1>something wrong</h1>")
    else:
        profile_form = ProfileForm(request.POST)
        info_form = InfoProfileForm(request.POST)
return render(request, 'accounts/registration.html',{'profile_form':profile_form,'info_form': info_form,})

Post a Comment for "Registration Form Not Saving Data In Profile Model, Using Extended Django User Model"