我有这个模特
class UserInfo(models.Model) :
userNumber = models.CharField(max_length=15)
userPin = models.CharField(max_length=7, unique=True)
def __str__(self) :
return str(self.userPin)
class UserFollows(models.Model) :
following = models.ForeignKey(UserInfo, on_delete=models.CASCADE, related_name='UserFollows.following+')
followers = models.ForeignKey(UserInfo, on_delete=models.CASCADE, related_name='UserFollows.followers+')
我需要userPin的内部联接。 此命令尝试错误
UserInfo.objects.filter(userPin__UserFollows__followers= '****')
Unsupported lookup 'UserFollows' for CharField or join on the field not permitted
。
答案 0 :(得分:0)
在模型中,userPin
是CharField,而不是FK。您可以通过反向关系加入UserInfo
和UserFollows
并用userPin
进行过滤:
UserInfo.objects.filter(user_follows__followers__userPin='value')