This may not be helpful but here is how I usually go about processing
model forms:

class Partner(models.Model):
    # this is your model, DB fields go in here

# This is your model form
class PartnerForm(forms.ModelForm):
   class Meta:
      model = Partner

# This is the view that displays a new partner form or processes the
form
def new(request):
    form = PartnerForm()
    if request.method=="POST":
        # if there is a post, they are sending in the form so re-
create the form from the post data
        form = PartnerForm(request.POST)
        if form.is_valid():
             p = form.save()   # save the form and store the resulting
Partner object in p
             return HttpResponseRedirect("/success")  # always
redirect after processing a form to revent refresh spam

    # if we got to this point it means it wasn't a POST and we didn't
process a form, or the form was invalid
   # either way, render whatever we had with errors and what not
    return render_to_response('new_partner_template.html', {'form':
form})

# This is a view to edit and existing parter
def edit(request, id):   # ID is the partners identifying number such
as primary key, SSN, whatever you want
    p = get_object_or_404(Partner, pk=id)   # this will throw a 404 if
they requested an invalid partner
    form = PartnerForm(instance=p)   # create a form pre-populated
with the partner data we just loaded
    if request.method=='POST':
        # now process the submitted form
        form = PartnerForm(request.POST, instance=p)   # this creats a
form using the database data AND the post data
        if form.is_valid():
             p = form.save()
             return HttpResponseRedirect('/success')

    # if we got down here, they didn't submit the form, or they did
and there were errors, so render it back
   return render_to_response('my_template.html', {'form': form})

This is how I do it, If you have any further questions I can try to
help. Please note this code was off the top of my head, so it may not
compile "out of the box"

Dan
--~--~---------~--~----~------------~-------~--~----~
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
-~----------~----~----~----~------~----~------~--~---

Reply via email to