“article_set”在哪里?来自 Django?
我目前正在开发 Django/Pinax 应用程序(我确信我的问题不是 Pinax 特定的,这就是主题标题中没有提到 Pinax 的原因),我正在尝试弄清楚整个框架是如何工作的。现在,我必须编写一个视图来将数据传递到模板。我只在 django 手册中看到它的完成:在手册中,ObjectName.objects.all() 简单地传递给 render_to_response() 。我的任务有点复杂,所以我试图了解它是如何在 pinax 应用程序“配置文件”中完成的,但完全失败了。
因此,profile.html
模板文件有这样一行:
{% for article in other_user.article_set.all %}
“other_user”是传递给views.py 中的 render_to_response() 的“User”类的实例。好的,但是article_set不是它的类变量。我未能在应用程序代码中的任何位置找到article_set描述,但发现更多类似调用形式的内容出现:
{% for bookmark_instance in other_user.saved_bookmarks.all.select_related %}
搜索Django文档仅导致这个页面,没有告诉'article_set'到底是什么。
什么是article_set?它在哪里定义以及它如何工作?任何答案或只是文档链接都非常感谢。谢谢。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
请参阅有关遵循“向后”关系的文档< /a>.
还有一些示例。
See the documentation on following the "backward" relations.
There are also some examples.
这是一个由来自
Article
模型的ForeignKey
或ManyToManyField
。It's an artificial field created by a
ForeignKey
orManyToManyField
from theArticle
model.