Re: Creating an "Edit Page"
You might want to look into class based views:
On Monday, August 12, 2013 2:50:00 PM UTC-7, Liz wrote:
-- These are then extended to create "generic views" that handle a lot of these common patterns.
there's something called an "UpdateView" that handles this exact pattern: https://docs.djangoproject.com/en/dev/ref/class-based-views/generic-editing/#django.views.generic.edit.UpdateView
However, it's also ALWAYS good to see how these things work in a functional view as well. It'll help in understanding and for that you'll want start by reading about ModelForms:
Near the top of that page they have some sample code -
# Creating a form to change an existing article. >>> article = Article.objects.get(pk=1) >>> form = ArticleForm(instance=article)
On Monday, August 12, 2013 2:50:00 PM UTC-7, Liz wrote:
I've been struggling in creating an edit page and I need help, please!The goal is to get the user to search a record and when they click on the link, I would like to use form.p with the values it finds from the database.For example if they search a name and click on the person that is already stored in the database, they should be redirected to a page where it shows a form with the person's information and the user should be able to edit and save the changes.I would appreciate any time of help to accomplish this.I've been thinking to do the following but I do not believe I'm on the right track:html page<form enctype="multipart/form-data" action method="post" id="{{person.id}}"> <ul>{{form.as_p}}</ul><input type='submit' name='submit' value='save''></form>viewdef person(request, person_id=1):return render_to_response('edit.html', {'article': Data.objects.get(id=person_id) })
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.
For more options, visit https://groups.google.com/groups/opt_out.
0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home