On Sep 9, 4:47 am, "Efrain Valles" <[EMAIL PROTECTED]> wrote:
> Hello all,
>
> I have a basic question, I am currently adding new items using a form
> that is generated using ModelForms, I have html for the form I need
> using {{ form.as_table }} in the html. Now I am trying to do CRUD for
> data update and I was wondering if I could use the same form generated
> with ModelForms adding the values for the fields of a specific item.
> or do I have to do the form defining the class again and write the
> corresponding html code ?
>
> thanks in advance
>
> Efrain Valles

Just pass the model instance when instantiating the form to
prepopulate it with the values:
myinstance = MyModel.objects.get(pk=val)
form = MyModelForm(instance=myinstance)

and when you're saving the result:
form = MyModelForm(data=request.POST, instance=myinstance)
form.save()

See here:
http://docs.djangoproject.com/en/dev/topics/forms/modelforms/#the-save-method

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