On Monday 01 June 2009 01:38:30 adelaide_mike wrote: > I found a really clear explanation of creating and updating database > objects in SAMS TeachYourself Django, but it appears to be for v > 0.96. > > I have looked at "Creating forms from models" in the documentation, > and about one-third the way down it shows the following: > > # Create a form instance from POST data. > > >>> f = ArticleForm(request.POST) > > # Save a new Article object from the form's data. > > >>> new_article = f.save() > > # Create a form to edit an existing Article. > > >>> a = Article.objects.get(pk=1) > >>> f = ArticleForm(instance=a) > >>> f.save() > > # Create a form to edit an existing Article, but use > # POST data to populate the form. > > >>> a = Article.objects.get(pk=1) > >>> f = ArticleForm(request.POST, instance=a) > >>> f.save() > > I understand what these code fragments are intended to do (I think) > but I am not clear as to how to use them. Can someone point me to a > more fully displayed example? TIA > > Mike
Here's an example from my code, does this help? Tim. def edit_result(request, pResultSerial): """ Edit a single result row """ lContestResult = get_object_or_404(ContestResult, pk=pResultSerial) if request.user != lContestResult.owner: raise Http404() if request.method == 'POST': form = ContestResultForm(request.POST, instance=lContestResult) if form.is_valid(): form.save() return HttpResponseRedirect(reverse('bbr.contests.views.single_contest_event', args=[lContestResult.contest_event.contest.slug, lContestResult.contest_event.date_of_event])) else: form = ContestResultForm(instance=lContestResult) return render_auth(request, 'contests/edit_result.html', {'form': form, 'ContestResult' : lContestResult}) --~--~---------~--~----~------------~-------~--~----~ 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---