Kevin
unread,Jul 13, 2012, 4:00:03 PM7/13/12Sign in to reply to author
Sign in to forward
You do not have permission to delete messages in this group
Either email addresses are anonymous for this group or you need the view member email addresses permission to view the original message
to django...@googlegroups.com
I'm new to Django so hopefully this will be trivial to solve.
I have a table of data I display in a view along with a simple form to add a new row of data to the table:
def my_data_view(request, data_id):
myData = MyData.objects.get(pk=data_id)
if request.method == 'POST':
myForm = MyForm(request.POST)
else:
myForm = MyForm()
return render_to_response('myapp/mydata.html',
{ 'my_data' : myData,
'my_form' : myForm,},
context_instance=RequestContext(request))
def add_new_row(request, data_id):
myData = MyData.objects.get(pk=data_id)
if request.method == 'POST':
myForm = MyForm(request.POST)
if myForm.is_valid():
# TODO insert new time into DB
return HttpResponseRedirect(reverse('myapp.views.mydata', args=(myData.id,)))
return my_data_view(request, data_id)
This works when I submit a valid form. However submitting an invalid form directs me from myapp/mydata/3 to myapp/mydata/addNewRow/3 which means when I submit the corrected form it posts to myapp/addNewRow/addNewRow/3 which is obviously not what I want. Any suggestions?
Thanks much!
Kevin