我一直在阅读和关注Django教程https://docs.djangoproject.com/en/1.3/intro/tutorial01/我在Xubuntu 12.04 LTS虚拟机上运行Django 1.3.1和Python 2.7.3,如果重要的话,还有512 MB RAM。
实际上我找到了确切的问题,但参考文献似乎已经过时了。有没有人有可行的参考链接? Where does 'article_set' come from in Django?
提前谢谢。
答案 0 :(得分:1)
Django执行ForeignKey查找以建立相关对象之间的关系。
这些关系是作为_set
def get_accessor_name(self):
# This method encapsulates the logic that decides what name to give an
# accessor descriptor that retrieves related many-to-one or
# many-to-many objects. It uses the lower-cased object_name + "_set",
# but this can be overridden with the "related_name" option.
if self.field.rel.multiple:
# If this is a symmetrical m2m relation on self, there is no reverse accessor.
if getattr(self.field.rel, 'symmetrical', False) and self.model == self.parent_model:
return None
return self.field.rel.related_name or (self.opts.object_name.lower() + '_set')
else:
return self.field.rel.related_name or (self.opts.object_name.lower())
Django源代码执行此操作(models/related.py
)