在笔者的模型:'模型' 对象不是可迭代
century = models.ManyToManyField(Century)
鉴于:
a = get_object_or_404(Author.objects, id=id)
s = Author.objects.filter(century__in=a).order_by('?')[:3]
错误:
Exception Value: 'Author' object is not iterable
有什么不对?作者可能属于两个世纪,我想从他的世纪/世纪中获得3位随机作者。
get_object_or_404确实可以与Author.objects一起使用。 – UnLiMiTeD 2013-02-15 21:51:08
@UnLiMiTeD:赶上!查看更新。 – 2013-02-15 22:07:40