Python 如何从django查询集检索项目?
我试图在queryset中获取视频元素,但检索时遇到问题Python 如何从django查询集检索项目?,python,django,view,model,django-queryset,Python,Django,View,Model,Django Queryset,我试图在queryset中获取视频元素,但检索时遇到问题 user_channel = Everything.objects.filter(profile = request.user, playlist = 'Channel') print user_channel[0] #returns the first result without error print user_channel[0]['video'] #returns error Models.py: class Every
user_channel = Everything.objects.filter(profile = request.user, playlist = 'Channel')
print user_channel[0] #returns the first result without error
print user_channel[0]['video'] #returns error
Models.py:
class Everything(models.Model):
profile = models.ForeignKey(User)
playlist = models.CharField('Playlist', max_length = 2000, null=True, blank=True)
platform = models.CharField('Platform', max_length = 2000, null=True, blank=True)
video = models.CharField('VideoID', max_length = 2000, null=True, blank=True)
video_title = models.CharField('Title of Video', max_length = 2000, null=True, blank=True)
def __unicode__(self):
return u'%s %s %s %s %s' % (self.profile, self.playlist, self.platform, self.video, self.video_title)
用户频道[0]
不是字典。使用
user_channel[0].video
用户频道[0]
不是字典。使用
user_channel[0].video
试试这个,你会得到基于过滤器的视频列表
user_channel = Everything.objects.filter(profile = request.user, playlist = 'Channel')
video = [x.video for x in user_channel]
print video/print video[0]
试试这个,你会得到基于过滤器的视频列表
user_channel = Everything.objects.filter(profile = request.user, playlist = 'Channel')
video = [x.video for x in user_channel]
print video/print video[0]
您是否尝试了
用户频道[0]。视频
?您是否尝试了用户频道[0]。视频
?