When querying in django say People.objects.all(pk=code), what does pk=code mean?
When querying in django say People.objects.all(pk=code) , what does pk=code mean?
Share
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
It’s a query to get the People object that has a primary key of whatever the value of “code” is.
By default, all Django model instances have a primary key that uniquely identifies the object. Generally it’s an auto-incrementing integer, but you could define it to be whatever you want, so long as it’s certain to be unique.
http://docs.djangoproject.com/en/dev/topics/db/models/#id1
Edit: Now that I look at the code snippet a little closer, rather than just assuming what it said, it doesn’t make much sense. The all() method should be a get(). It doesn’t make any sense to give a pk to all() since it just returns all the objects of that type.
http://docs.djangoproject.com/en/dev/ref/models/querysets/#all
http://docs.djangoproject.com/en/dev/ref/models/querysets/#id5