On 11/7/07, David Larlet <[EMAIL PROTECTED]> wrote:
> Unfortunately, what happens with my Form is exactly what I'd like to do:
> create a generic form from a Form class which define fields (with
> widgets, etc) and methods and which is initialized with the content of
> the instance. That seemed more natural to me instead of dealing with
> fields, form and eventually form_for_fields... I know that those
> functions are just shortcuts but it works very well in terms of
> genericity and my main concern here is to integrate a generic way to
> handle forms for resources in restapi.

Well, from what you posted before, your forms aren't really all that
"generic", so I'm not sure exactly what you're trying to accomplish.
If you're just looking for a simple way to populate a form's initial
values with those from a matching model, try this:

foo = Foo.objects.get(id=1)
form = FooForm(initial=foo.__dict__)

Now, I haven't tested that, so I make no guarantees, but at a quick
glance, it looks like it should do what you're looking for. Remember,
form_for_instance is for creating a form *and* populating it, not just
for populating an existing form. Also, keep in mind that you won't
have the save() method on FooForm unless you add it yourself, so I'm
really not sure how this would be any better than just using
form_for_instance as-is.

-Gul

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Django developers" 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-developers?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to