0
我想要做的就是通過 User.objects.get(PK = 1).profile.friends使用特定foriegnkey 我做的這一切userimages。所有()。values_list('userimages')無法獲取模型foriegn關鍵
但是這就是我得到的。我覺得奇怪的是,uservideo模型與userimages非常相似,但userimages無法解決。
FieldError: Cannot resolve keyword 'userimages' into field. Choices are: about_me, display_image, friends, id, nick_name, owner, owner_id, user, user_id, uservideo
車型
class UserImages(models.Model):
owner = models.ForeignKey('auth.User', related_name='UserImages')
user=models.ForeignKey(Profile,related_name="profile_owner")
# highlighted = models.TextField(default=None,blank=True,null=True)
image=models.ImageField()
pub_date=models.DateTimeField(default=now)
class UserVideo(models.Model):
owner = models.ForeignKey('auth.User', related_name='UserVideo')
# highlighted = models.TextField(default=None,blank=True,null=True)
user=models.ForeignKey(Profile)
image=models.FileField()
pub_date=models.DateTimeField(default=now)
有沒有辦法爲多個用戶獲取queryset? –
@prashanthambati是的,你可以使用'__in'查找:'UserImages.objects.filter(user__in = [1,2,3])' –