Hi all,
I read that Django knows the difference between a new and a updated record, but
it replicates the customer if I don't set the customer_id before a
customer.save. Would somebody please shoot at my code and tell me where the
room for improvement is hiding?
def customer_edit(request, customer_id):
if request.method == 'POST':
form = CustomerForm(request.POST)
if form.is_valid():
customer = form.save(commit=False)
customer.id = customer_id
customer.save()
return HttpResponseRedirect('/myapp/customer/'+str(customer.id))
else:
customer = get_object_or_404(Customer, pk=customer_id)
form = CustomerForm(instance=customer)
return render_to_response(template+'/customer_edit.html', {'form': form,
'customer': customer })
Thanx!!
Gerard.
--
urls = { 'fun': 'www.zonderbroodje.nl', 'tech': 'www.gp-net.nl' }
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Django users" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---