Opened 19 years ago

Closed 19 years ago

Last modified 18 years ago

#1663 closed defect (fixed)

problem(?) in vote() function of views.py in tutorial04.txt of magic-removal /docs

Reported by: jheasly@… Owned by: Jacob
Component: Documentation Version: magic-removal
Severity: normal Keywords:
Cc: Triage Stage: Unreviewed
Has patch: no Needs documentation: no
Needs tests: no Patch needs improvement: no
Easy pickings: no UI/UX: no

Description

I'm heeding Adrian's call for m-r doc nitpicks.

My Python is pretty basic, but in the section of the m-r tutorial04.txt where the vote() function is defined, the code has this:

def vote(request, poll_id):
    ...
    selected_choice = p.choice_set.filter(pk=request.POST['choice'])
    ...
    selected_choice.votes += 1
    ...

The pk= lookup returns a selected_choice that is a <class 'django.db.models.query.QuerySet'>, but that particular creature has no attribute votes to be incremented by the code a few lines further down, so it throws an AttributeError exception. I'm sure it's just a minor tweak of how you talk to the QuerySet class, but that is black magic that's way beyond me.

FWIW, I was able to poke around and find the votes attibute in the list returned by doing a ...

    dir(selected_choice.model.objects.all()[0])

... but that's too ugly to be believed. So, anyways, I think there may be a problem here (but I could be wrong).

Change History (2)

comment:1 by Dave St.Germain <dcs@…>, 19 years ago

it should be p.choice_set.get(pk=request.POST['choice'])

comment:2 by anonymous, 19 years ago

Resolution: fixed
Status: newclosed
Note: See TracTickets for help on using tickets.
Back to Top