我的模型设置如下:
class Post(models.Model):
name = models.CharField(max_length=10)
class Comment(models.Model):
post = models.ForeignKey(Post,related_name='comments')
name = models.CharField(max_length=10)
当我想获取帖子中的所有评论时somepost.comments()
我收到以下错误:
>> somepost.comments()
Traceback (most recent call last):
File "<console>", line 1, in <module>
File "a_path/django/db/models/fields/related.py", line 693, in __call__
manager = getattr(self.model, kwargs.pop('manager'))
KeyError: 'manager'
它应该是somepost.comments.all()
.
somepost.comments
返回一个查询集。all
访问其中的对象。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)