开发者

Django syntax obj.pk

i am trying to understand the syntax ".pk" in Django. Is ".pk" a reference to a file or reference to a Primary Key...As the ".pk" including a dot so it is hard to google for the answer. Can someone tell me..

For instance

开发者_如何学Python
        current_tags = list(self.filter(items__content_type__pk=ctype.pk,
                                    items__object_id=obj.pk))


obj.pk refers to the object property which acts as an alias to the primary key.

See http://docs.djangoproject.com/en/dev/ref/models/instances/#the-pk-property for details.

As for how to google for it, I stumbled upon that reference by google for "+django Model.pk" since obj if of class models.Model.

In fact, When looking for django related docs, the easiest would be to use the search box in the http://docs.djangoproject.com site. If you really want to use google, include +site:docs.djangoproject.com to your search string, e.g "pk +site:docs.djangoproject.com".


The usability of 'pk' field is that you can use someone other's model which has the primary key field called other than 'id'. In other words the 'pk' field gives you a flexibility to use model's primary key not knowing what this key actually is.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜