I guess on Part 4 is what I need...

So hmmm.

def vote(request, poll_id):
    p = get_object_or_404(Poll, pk=poll_id)
    try:
        selected_choice = p.choice_set.get(pk=request.POST['choice'])
    except (KeyError, Choice.DoesNotExist):
        # Redisplay the poll voting form.
        return render_to_response('polls/detail.html', {
            'poll': p,
            'error_message': "You didn't select a choice.",
        }, context_instance=RequestContext(request))
    else:
        selected_choice.votes += 1
        selected_choice.save()
        # Always return an HttpResponseRedirect after successfully dealing
        # with POST data. This prevents data from being posted twice if a
        # user hits the Back button.
        return HttpResponseRedirect(reverse('polls.views.results', 
args=(p.id,)))

So originally:

        selected_choice = p.choice_set.get(pk=request.POST['choice'])

this requests the submitted choice from the POST data and 

The part that says:

        selected_choice.votes += 1
        selected_choice.save()

Actually saves the choice to the database?

Is it just two lines? requesting the data form request.POST and then that 
variable.save() to store it in the database?

JJ

On Wednesday, July 11, 2012 12:31:44 AM UTC-4, Lee Hinde wrote:
>
>
> On Jul 10, 2012, at 8:48 PM, JJ Zolper wrote:
>
> I honestly just have a general question.
>
> If I have one database set in my settings file in settings.py and I try to 
> execute a simple HTML Form using 'POST' how do I get that data into my 
> PostgreSQL database?
>
> In my view do I have to interface with my model and thus the model takes 
> care of the rest?
>
> https://docs.djangoproject.com/en/1.4/topics/forms/modelforms/
>
> This link seems to be down the right road I think?
>
> I'm sorry if this question does not make a lot of sense but I really am 
> trying to find some direction as to how once I have a view, model, urlconf, 
> and settings file with a database tied to it (i checked using the import 
> django.db connection/cursor test) how do I get the request.POST data sent 
> to my database?
>
> Thanks,
>
> JJ
>
> I recommend the tutorial. It walks you through the process, soup to nuts.
>
> https://docs.djangoproject.com/en/dev/intro/tutorial01/
>
>

-- 
You received this message because you are subscribed to the Google Groups 
"Django users" group.
To view this discussion on the web visit 
https://groups.google.com/d/msg/django-users/-/WrL0VQrqMvQJ.
To post to this group, send email to [email protected].
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