Django模型中int()的文字无效

时间:2012-12-15 23:19:04

标签: python django exception model

我收到一个错误的无效文字int()与基数10:sharat,我不知道如何解决它。有什么建议吗?

friend = 'sharat'
user_playlists = Everything.objects.filter(profile = friend).values('playlist').distinct()

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)

1 个答案:

答案 0 :(得分:3)

首先需要通过该名称获取用户,然后由该用户进行过滤,而不是按用户名进行过滤。或者(可能更好),你可以让Django以更有效的方式做到这一点,可能涉及一个连接:

user_playlists = Everything.objects.filter(profile__username=friend).values('playlist').distinct()