class FriendshipManager(models.Manager):
def are_friends(self, user1, user2):
if self.filter(from_user=user1, to_user=user2).count() > 0:
return True
if self.filter(from_user=user2, to_user=user1).count() > 0:
return True
return False
我找到了伯爵() 所以我试试看, 但它错了
^{pr2}$或者
a='ssada'
print a.count()
为什么我的代码运行错误,但是FriendshipManager可以运行,谢谢 我的英文不是很好,请尽量不要用我的代码
如果要确定列表的长度/大小,我想您应该使用}。
len(a)
,而不是{a.count()
实际上需要一个参数。它统计一个值的出现次数。例如:莱恩是那个案子的正确人选。在
这里的问题是您混淆了两个同名的方法。在
{account在cython>序列中的出现次数正好描述了在cd1>中出现的次数
但是,您引用的代码来自Django模型。在这里,对filter对象调用
count()
是SQL分组函数COUNT
的别名,该函数汇总匹配行的数量。在本质上,初始示例中的}根本不是相同的方法。在
count
和之后两个示例中的{相关问题 更多 >
编程相关推荐