I've been playing around with newforms (with a custom form) and I was
just wondering if anyone else has run into the same situation and I'm
curious as to what solutions others have come up with.  Basically, I
just want to edit an instance and I've been consistently writing the
following piece of code in my edit views.

if request.method == 'POST':
     # Fill in custom form with request post data
     form = CustomForm(data = request.POST.copy())
     if form.is_valid():
          instance = get_object_or_404(InstanceClass, pk =
request["object_id"])
          for key in form.clean_data:
               instance.__setattr__(key, form.clean_data[key])
          instance.save()
          return HttpResponseRedirect(instance.get_absolute_url())

Fairly straightforward, if it's a POST, fill in the custom form with
the data.  If the data validates, retrieve the instance object the
form refers to, and overwrite data from the form into the instance,
then update.

I'm just wondering if this what others have been doing?  Seems cludgy
to me. :)

Thanks,
Ryan


--~--~---------~--~----~------------~-------~--~----~
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 [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to