gpt4 book ai didi

python - 如何从 django 查询集中检索项目?

转载 作者:太空宇宙 更新时间:2023-11-03 19:08:36 25 4
gpt4 key购买 nike

我正在尝试获取查询集中的视频元素,但在检索它时遇到问题。

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

模型.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)

最佳答案

尝试一下,您可以获得基于过滤器的视频列表

user_channel = Everything.objects.filter(profile = request.user, playlist = 'Channel')
video = [x.video for x in user_channel]
print video/print video[0]

关于python - 如何从 django 查询集中检索项目?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13781789/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com