Where does 'article_set' come from in Django?

為{幸葍}努か 提交于 2019-12-24 08:52:37

问题


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.


回答1:


See the documentation on following the "backward" relations.

There are also some examples.




回答2:


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



来源:https://stackoverflow.com/questions/2303923/where-does-article-set-come-from-in-django

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!