def edit_address(request, addressID): current = get_object_or_404(Address, pk=addressID, owner = request.user) if request.method == 'POST': form = AddressForm(request.POST, instance=current) if form.is_valid(): address = form.save() return HttpResponseRedirect('/profile/e/edit') else: form = AddressForm(instance=current) return render_to_response('profile/newAddress.html', {'form':form}, context_instance=RequestContext(request))
def new_address(request): if request.method == 'POST': form = AddressForm(request.POST) if form.is_valid(): newAddress = form.save(commit=False) newAddress.owner = request.user newAddress.save() request.user.profile.addresses.add(newAddress) return HttpResponseRedirect('/profile/e/edit') else: form = AddressForm() return render_to_response('profile/newAddress.html', {'form' : form}, context_instance=RequestContext(request))
def edit_address(request, addressID): current = get_object_or_404(Address, pk=addressID, owner=request.user) if request.method == 'POST': form = AddressForm(request.POST, instance=current) if form.is_valid(): address = form.save() return HttpResponseRedirect('/profile/e/edit') else: form = AddressForm(instance=current) return render_to_response('profile/newAddress.html', {'form': form}, context_instance=RequestContext(request))
def new_address(request): if request.method == 'POST': form = AddressForm(request.POST) if form.is_valid(): newAddress = form.save(commit=False) newAddress.owner = request.user newAddress.save() request.user.profile.addresses.add(newAddress) return HttpResponseRedirect('/profile/e/edit') else: form = AddressForm() return render_to_response('profile/newAddress.html', {'form': form}, context_instance=RequestContext(request))