Question

When i have this view, It only change username a password from first Form, but it would save any data from second form. Why?

if request.method == 'POST': # If the form has been submitted...
    username_a_heslo = UserCreationForm(request.POST, prefix = "začátek")
    přidat_údaje = UcitelZmenaForm(request.POST, prefix = "konec")
    if username_a_heslo.is_valid() and přidat_údaje.is_valid(): # All validation rules pass
        změnajména = request.user
        změnajména.username = username_a_heslo.cleaned_data["username"]
        změnajména.save()
        zmenahesla=request.user.set_password(username_a_heslo.cleaned_data["password1"])
        # primary = username_a_heslo.save()
        cast_form = Ucitel.objects.all().filter(user=request.user)
        form = UcitelZmenaForm(přidat_údaje.cleaned_data, instance=cast_form[0])
        form.save
        #b = přidat_údaje.save()
        return HttpResponseRedirect('/hlavni_stranka/')
else:
    username_a_heslo = UserCreationForm(prefix = "začátek")
    přidat_údaje = UcitelZmenaForm(prefix = "konec")
return render(request, 'registration/prihlasen.html', {'prvni_prihlaseni':prvni_prihlaseni,'první_form': username_a_heslo,'druhý_form':přidat_údaje})
Was it helpful?

Solution

You did not call the function on the second one, you only have form.save when you need form.save().

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top