Django ';相关经理';对象不是iterable typeerror
我想获得用户正在关注的所有配置文件,并将它们显示在单独的div中(img、name、email)。我可以得到“following”的总数,但是,我无法迭代抛出following并逐个用户显示Django ';相关经理';对象不是iterable typeerror,django,Django,我想获得用户正在关注的所有配置文件,并将它们显示在单独的div中(img、name、email)。我可以得到“following”的总数,但是,我无法迭代抛出following并逐个用户显示 Exception Value: 'RelatedManager' object is not iterable 感谢您的帮助 仪表板: <p>{{ user.following.count }}</p> {% for guest in user.f
Exception Value:
'RelatedManager' object is not iterable
感谢您的帮助
仪表板:
<p>{{ user.following.count }}</p>
{% for guest in user.following %}
<div class="container-videos-card">
<div class="videos-card-details">
<h4 class = "container-videos-card-title">{{ guest.email }}</h4>
</div>
</div>
{% endfor %}
使用user.following.all,但我只能使用pk、follower\u id、following\u id访问该表。我如何访问其他属性,如配置文件用户名、配置文件图片?
guest.Profile.Profile\u图片
?
class User(AbstractBaseUser, PermissionsMixin):
email = models.EmailField(unique=True, null = False)
username = models.CharField(max_length=264, null = True, blank = True)
class Profile(models.Model):
user = models.OneToOneField(User, on_delete=models.CASCADE, related_name='profile')
full_name = models.CharField(max_length=264,null = True, blank = True)
username = models.CharField(max_length=264, null = True, blank = True)
profile_picture = models.ImageField(upload_to='profile_pictures/%Y/%m/%d/', blank = True)
class Follow(models.Model):
follower = models.ForeignKey(User, on_delete=models.CASCADE, related_name="follower")
following = models.ForeignKey(User, on_delete=models.CASCADE, related_name="following")