thank you, Shawn, for posting your working and tested example.  It
answered my questions (basically the same as the original post on this
thread) and got my head clear.

I agree in general with the point that the Django docs are not really
complete on this issue; I'd like it if the Forms/ModelForms would
throw out a complete CRUD example and explain each bit of it.

- dan




On Jul 21, 11:23 pm, Shawn Milochik <shawn.m...@gmail.com> wrote:
> To expand on  what Dan said with a full (tested and working) example:
>
> In urls.py:
>
>      (r'^partner/$', 'partner_page'),
>      (r'^partner/(?P<partner_id>\d+)/$', 'partner_page'),
>
> In the form tag of your template:
>      <form id="approval_form" method="post" action="/partner/{% if  
> partner_id %}{{ partner_id}}/{% endif %}">
>
> The view:
>
> @login_required
> def partner_page(request, partner_id = None):
>
>      if partner_id:
>          #existing partner
>          partner_instance = get_object_or_404(partner, pk = partner_id)
>      else:
>          #new partner
>          partner_form = partnerForm()
>          partner_instance = None
>
>      if request.POST:
>          post_data = request.POST.copy()
>          partner_form = partnerForm(post_data, instance =  
> partner_instance)
>
>          if partner_form.is_valid():
>              the_partner = partner_form.save()
>              partner_id = the_partner.id
>
>      template_file = 'partner.html'
>
>      context = {
>          'partner_form': partner_form,
>          'partner_id': partner_id,
>      }
>
>      return render_to_response(template_file, context,  
> RequestContext(request))

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To post to this group, send email to django-users@googlegroups.com
To unsubscribe from this group, send email to 
django-users+unsubscr...@googlegroups.com
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to