[Fixed]-How do you write a save method for forms in django?

17👍

this could help you

def save(self):
    data = self.cleaned_data
    user = User(email=data['email'], first_name=data['first_name'],
        last_name=data['last_name'], password1=data['password1'],
        password2=data['password2'])
    user.save()
    userProfile = UserProfile(user=user,gender=data['genger'],
        year=data['year'], location=data['location'])
    userProfile.save()

7👍

The prefix argument (also on ModelForm by inheritance) to the constructor will allow you to put multiple forms within a single <form> tag and distinguish between them on submission.

mf1 = ModelForm1(prefix="mf1")
mf2 = ModelForm2(prefix="mf2")
return render_to_response(..., {'modelform1': mf1, 'modelform2': mf2}, ...)

<form method="post">
{{ modelform1 }}
{{ modelform2 }}
 ...
</form>

Leave a comment