On Thu, Dec 3, 2009 at 4:17 PM, Todd Blanchard <[email protected]> wrote:
> All the tutorials on forms discuss creating a new record.
>
> I've got a record in the database, I want to fetch it, plunk its values into 
> a form, let the user edit it and save it.
>
> I don't see how to conveniently put the model's values into the form.  It 
> seems the form wants a dictionary of values, so how to convert a model object 
> to a dict?
>
> -Todd Blanchard
>
> --
>
> 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.
>
>
>

Assuming you'd use a ModelForm[1] to update the records, all you need
to do is something like the following:

my_record = Record.objects.get(id = 1)
my_form = MyRecordModelForm(instance = my_record)

You will then have a form with the 'values' on the fields pre-set.
Users can then edit the form to their hearts content, submit it and
you can the process the form[2] as you would normally do with a
ModelForm.


[1] - http://docs.djangoproject.com/en/dev/topics/forms/modelforms/
[2] - 
http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#the-save-method

-- 

Best,

R

--

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