Since you are editing, you need to get the form object using the object instance. In your case, it tries to create a new object, but since this pk
already exists, it is throwing the integrity error.
form = ContactForm(request.POST, instance=contact_obj)
Move the creation of contact_obj
up to the beginning of the view method
Something like this:
from django.core.exceptions import MultipleObjectsReturned
def contact(request, template_name):
try:
contact_obj = Contact.objects.get(user=request.user)
except: #You might want to handle multiple objects returned case here too..
contact_obj = None
form = ContactForm(instance=contact_obj)
if request.method == "POST":
form = ContactForm(request.POST, instance=contact_obj)
if form.is_valid():
obj = form.save(commit=False)
obj.user = request.user
obj.save()
return HttpResponseRedirect('/newuser/step2/')
return render_to_response(template_name, RequestContext(request, {'form' : form}))