我正在创建一个基于社区的网站,当我创建个人档案模型时,我将所有者作为用户的外键,但是在我看来
args['user'] = user = request.user
args['profile'] = UserCommunityProfile.objects.filter(owner = user)
我也尝试做owner_id__exact = user.id
和owner_id = user.id
,但还是不做
在模板中,如果我做{{ profile.count }}
,我什么也没得到,为什么?
这是我的模型.py
class UserCommunityProfile(models.Model):
class Meta():
db_table = "user_profile"
verbose_name = "User Community Profile"
verbose_name_plural = "Users Community Profiles"
owner = models.ForeignKey(
User,
related_name="user_profile_user_key",
verbose_name="owner of the profile",
blank=False,
null=False,
on_delete = models.CASCADE,
)
DOB = models.DateField (
auto_now=False,
auto_now_add=False,
)
user_description = models.TextField (
blank=False,
null=False,
)
profile_picture = models.ImageField(
upload_to='community-profile-pictures',
default='default.png'
)
profile_creation = models.DateTimeField(
auto_now_add=True
)
def __str__(self):
return self.owner.username