Python 哪里是';化身集';在askbot中定义的用户方法?
下面是/askbot/models文件夹中的_init___u;.py文件的一部分:Python 哪里是';化身集';在askbot中定义的用户方法?,python,django,askbot,Python,Django,Askbot,下面是/askbot/models文件夹中的_init___u;.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. "
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\u set.count(),我认为它应该是/Django/Contrib/auth中用户类中的本机方法,或者是由用户添加的方法
但我似乎找不到这种“化身集”方法的定义
谢谢这是一种反向关系,当您定义指向模型的ForeignKey时,Django会自动添加这种关系。请参阅。您的答案就在我发布自己的答案之前,我刚刚了解了您的解释。谢谢