django中如何设置两个相同的外键

class Attention(models.Model):
    """
    用户关注模块
    """
    follower = models.ForeignKey(User, on_delete=models.CASCADE, related_name='follower', verbose_name='关注用户')
    followed = models.ForeignKey(User, on_delete=models.CASCADE, related_name='followed', verbose_name='被关主用户')
    has_follow = models.BooleanField(default=True, verbose_name='判断是否已经关注')

related_name='followed'
如何获取对应的值
根据related_name的值获取
关注的所有用户: follower_list = user.follower.all()
被关注的用户:followed_list = user.followed.all()

你可能感兴趣的:(django中如何设置两个相同的外键)