Hello DR, Sorry I was misleading. I was actually referencing a section form the djangobook, chapter 7 -- not the tutorial.
And I have read the link you you sent, but as in other places in the documentation, it seems the save command is only explained when in the shell. I can't figure out how to translate that to my views. On May 12, 4:44 pm, Daniel Roseman <roseman.dan...@googlemail.com> wrote: > On May 12, 10:14 pm, "asdjohn...@gmail.com" <asdjohn...@gmail.com> > wrote: > > > > > Hello, > > > I have just started with Django a few days ago and have gone through > > the tutorial but can't figure out how to save user inputed data to the > > database. > > > For example, in chapter 7 we learn how to collect data and use it to > > send an email: > > > def contact(request): > > errors = [] > > if request.method == 'POST': > > if not request.POST.get('subject', ''): > > errors.append('Enter a subject.') > > if not request.POST.get('message', ''): > > errors.append('Enter a message.') > > if request.POST.get('email') and '@' not in request.POST > > ['email']: > > errors.append('Enter a valid e-mail address.') > > if not errors: > > send_mail( > > request.POST['subject'], > > request.POST['message'], > > request.POST.get('email', 'nore...@example.com'), > > ['siteow...@example.com'], > > ) > > return HttpResponseRedirect('/contact/thanks/') > > return render_to_response('contact_form.html', > > {'errors': errors}) > > > But what if you just want to save that data to the database? I've > > played with swapping the "send_mail" with "save" but cannot seem to > > get the syntax down right. > > > This has to be something simple that I'm overlooking. Any help would > > be appreciated. > > Save it to the database where? You haven't associated it with a model, > here you're just taking arbitrary POST data and using it to send an > email. If you want to save to the database you need to define a model, > create an instance using your POST data, and save it. > > I don't know what book you are following (the tutorial doesn't have a > chapter 7), but you need to learn about ModelForms, which handle this > for you automatically. Look them up in the main > documentation:http://docs.djangoproject.com/en/dev/topics/forms/modelforms/ > -- > 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 django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---