尝试查询“收藏夹”模型以获取用户收藏的项目列表,然后查询不同的模型以从该查询中获取对象以呈现给模板,但我收到错误:“无效以 10 为底的 int() 的字面量"
查看该错误的所有其他实例,我找不到提问者实际上想要使用逗号分隔的整数列表的任何实例,所以我有点不知所措。
模型
class Favorite(models.Model):
# key should be the model name, id is the model.id, and user is the User object.
key = models.CharField(max_length=255, unique=True)
val = models.IntegerField(default=0)
user = models.ForeignKey(User)
class Admin:
list_display = ('key', 'id', 'user')
看法
def index(request):
favorites = Favorite.objects.filter(key='blog', user=request.user.pk)
values = ""
for favorite in favorites:
values += "%s," % favorite.val
#values = "[%s]" % values
blogs = Blog.objects.filter(pk__in=values)
return render_to_response('favorite/index.html',
{
"favorites" : favorites,
"blogs" : blogs,
"values" : values,
},
context_instance=RequestContext(request)
)
enter code here