原问题网址:
http://stackoverflow.com/questions/10535604/cannot-assign-must-be-a-instance-django
描述:
Not sure where the confusion here is. Scripter.title is a foreign key to
Book, so you must give it an actual Book, not a string.
当前所对应的值的表需要和想要获取过滤后的表有关联,不是随便什么值都可以,最好是A表.objects.filter(foreignkey = foreignkey‘s table.id)
本文解释了在 Django 模型中正确使用 ForeignKey 的方法。强调了在实例化包含 ForeignKey 的模型时,应传递关联模型的实际实例而非字符串。此外,文章还提供了一个具体的例子来展示如何在 QuerySet 中正确地使用过滤条件。
6014

被折叠的 条评论
为什么被折叠?



