Saturday, March 31, 2012

I don't get what Poll.objects.get(pk=1) does


I'm learning Django (I already know Python) and I'm following the
At the end of the tutorial there is a code where the programmer does:
p = Poll.objects.get(pk=1) .
I want to be sure if I understand it well.
Poll.object.get(pk=1) is returning the poll which primary key is 1 in
the DB, isn't it?
This is stored in p, which is actually the poll which pk is 1, so it's
itselft but with new class variables added (the other side of the
Foreign Keys). Is it correct?
This creates a new class variable called choice_set because Choise is
an other-side foreign key of poll.
This object (choise_set, of type RelatedManager) has a method create
that adds things to the set.

Did I understand it well??

Thank you,

(PS: sorry for my english )

You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to
To unsubscribe from this group, send email to
For more options, visit this group at

No comments:

Post a Comment