Friday, October 18, 2013

Re: Editing forms in django

On Fri, Oct 18, 2013 at 1:09 PM, amanjot kaur <kauramanjot35@gmail.com> wrote:
> What should I need to do in django, if I want to edit the information
> filled in django, like we edit our profile in facebook after filling
> once?

That means editing the already saved data?

Assuming you are using a ModelForm, use the instance keyword argument,
and pass the model you are updating.

So, if you have MyModel and MyModelForm, then your code might look like:

my_record = MyModel.objects.get(id=XXX)
form = MyModelForm(instance=my_record)

And then, when the user sends back data by POST:

form = MyModelForm(request.POST, instance=my_record)

Documentation is here:
http://docs.djangoproject.com/en/1.3/topics/forms/modelforms/


--
Sandeep Kaur
E-Mail: mkaurkhalsa@gmail.com
Blog: sandymadaan.wordpress.com

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAF66xG3rp5YHFCb6exXfj3m1RRvxyfG1oPUzw58UYY2EnChOMA%40mail.gmail.com.
For more options, visit https://groups.google.com/groups/opt_out.

0 Comments:

Post a Comment

Subscribe to Post Comments [Atom]

<< Home


Real Estate