I refactored this into a single view (similar to the Django form example) 
and it's working fine...not to mention it's much more DRY.

Feel free to disregard!

Kevin

On Friday, July 13, 2012 3:00:03 PM UTC-5, Kevin wrote:
>
> 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
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/YjQRiYfGyokJ.
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.

Reply via email to