[英]AttributeError: 'QuerySet' object has no attribute 'requests'
I have the following models: 我有以下型号:
class App(models.Model):
name = models.CharField(max_length=20)
...
class Request(models.Model):
...
app = models.ForeignKey(App)
...
When trying the following: 尝试以下操作时:
a = App.objects.all().prefetch_related('request_set')
for r in a.requests:
print r
It's giving: 它给:
AttributeError: 'QuerySet' object has no attribute 'requests'
Why is that? 这是为什么?
您使用了错误的属性来访问您的应用程序的要求-你需要使用a.request_set
(或设置related_name
在ForeignKey
定义是“要求”)。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.