下面是/askbot/model文件夹中__init__.py文件的一部分:
def user_update_avatar_type(self):
"""counts number of custom avatars
and if zero, sets avatar_type to False,
True otherwise. The method is called only if
avatar application is installed.
Saves the object.
"""
if 'avatar' in django_settings.INSTALLED_APPS:
if self.avatar_set.count() > 0:
self.avatar_type = 'a'
else:
self.avatar_type = _check_gravatar(self.gravatar)
else:
self.avatar_type = _check_gravatar(self.gravatar)
self.save()如您所见,在某种程度上,它调用self.avatar_set.count(),我认为它应该是本机在/Django/cont肋骨/auth的用户类中使用的方法,或者是User.add_to_class方法添加的方法,就像这个__init__.py文件中的许多其他方法一样。
但是我似乎找不到这个'avatar_set‘方法是在哪里定义的。
谢谢
发布于 2014-05-26 10:01:29
这是一种反向关系,在定义指向模型的ForeignKey时,Django会自动添加这种关系。见查询文档。
https://stackoverflow.com/questions/23867204
复制相似问题