Opened 10 years ago

Closed 10 years ago

Last modified 9 years ago

#1663 closed defect (fixed)

problem(?) in vote() function of 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: UI/UX:


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 ...


... 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 Changed 10 years ago by Dave St.Germain <dcs@…>

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

comment:2 Changed 10 years ago by anonymous

  • Resolution set to fixed
  • Status changed from new to closed
Note: See TracTickets for help on using tickets.
Back to Top