开发者

Where does 'article_set' come from in Django?

I am currently working on a Django/Pinax application (I'm sure my question is not Pinax-specific, that's why Pinax's not mentioned in the theme title), and I'm trying to figure out how the whole framework works.开发者_如何学运维 Right now, I have to write a view to pass data to a template. I've only seen it done in the django manual: In the manual, ObjectName.objects.all() is simply passed to render_to_response(). My task is somewhat more complicated, so I've tried to understand how it is done in a pinax application 'profiles', and failed completely.

So, profile.html template file has a line like this:

{% for article in other_user.article_set.all %}

'other_user' is an instance of the 'User' class passed to render_to_response() in views.py. Ok, but article_set is not its class variable. I've failed to find article_set description anywhere in the application code, but found more occurrences of something looking like the same form of call:

{% for bookmark_instance in other_user.saved_bookmarks.all.select_related %}

Searching Django docs only resulted in this page, not telling what 'article_set' exactly is.

What is article_set? Where is it defined and how does it work? Any answers or just documentation links are strongly appreciated. Thank you.


See the documentation on following the "backward" relations.

There are also some examples.


It's an artificial field created by a ForeignKey or ManyToManyField from the Article model.

0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜