Hi Chris,

On 12/01/07, Chris Rose <[EMAIL PROTECTED]> wrote:
> Felix Ingram wrote:
> > 3. Binding data - I'd like the form to handle editing of an instance.
> > I could construct a dictionary of values and pass it to the form as
> > per the docs but I'd like to just pass a model instance and have the
> > form sort things out. Is this advisable? If so then does anyone have
> > any pointers about what methods I need to implement?
>
> You can use the model instances __dict__:
>
> my_form = CreateForm(initial=model_instance.__dict__)
>
> Saves copying each field into a seperate dict or implementing any extra
> methods in your form.

This works quite well for simple forms but it won't populate m2m
fields and I need to tweak some fields for display.

Thanks for reminding me about __dict__ though. I do forget about it.

Regards,

Felix

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