tags:

views:

315

answers:

2

When querying in djangop say People.objects.all(pk=code)

Pk=code .Wht does it mean......

Thanks........

+2  A: 

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

Josh Wright
You mean to say its sumthing like where code=sumthing or orderby code?
Hulk
+2  A: 

Calling People.objects.all(pk=code) (calling all) will result in the pk=code being ignored and a QuerySet for all People returned.

Calling People.objects.get(pk=code) (calling get) will result in the People object with pk=code returned, or an error if not found.

Ben Edwards