Py学习  »  Django

官方文档的这部分是不是写的有问题?

cumt_ttr • 9 年前 • 3006 次点击  

https://docs.djangoproject.com/en/1.6/topics/db/examples/many_to_one/ 这个官方文档的这部分是不是有问题啊, Reporter是one的一方,Article是many的一方。。。。。。 ======== Querying in the opposite direction:

>>> Reporter.objects.filter(article__pk=1)
[<Reporter: John Smith>]
>>> Reporter.objects.filter(article=1)
[<Reporter: John Smith>]
>>> Reporter.objects.filter(article=a)
[<Reporter: John Smith>]

>>> Reporter.objects.filter(article__headline__startswith='This')
[<Reporter: John Smith>, <Reporter: John Smith>, <Reporter: John Smith>]
>>> Reporter.objects.filter(article__headline__startswith='This').distinct()
[<Reporter: John Smith>]
Python社区是高质量的Python/Django开发社区
本文地址:http://www.python88.com/topic/675
 
3006 次点击  
文章 [ 2 ]  |  最新文章 9 年前
cumt_ttr
Reply   •   1 楼
cumt_ttr    9 年前

搞清楚了,是related_name惹的,我在ForeignKey上添加了related_name

cumt_ttr
Reply   •   2 楼
cumt_ttr    9 年前

报类似的错误 FieldError: Cannot resolve keyword 'article' into field. Choices are: 。。。。