简体   繁体   English

AttributeError:“ QuerySet”对象没有属性“ requests”

[英]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_nameForeignKey定义是“要求”)。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 AttributeError:“ QuerySet”对象没有属性“ add” - AttributeError: 'QuerySet' object has no attribute 'add' AttributeError at /'QuerySet' 对象没有属性 'users' - AttributeError at / 'QuerySet' object has no attribute 'users' AttributeError: 'QuerySet' 对象没有属性 'save' - AttributeError: 'QuerySet' object has no attribute 'save' AttributeError: 'QuerySet' object 没有属性 'requestedDate' - AttributeError: 'QuerySet' object has no attribute 'requestedDate' /addtowatchlist/5 处的 AttributeError:“QuerySet”object 没有属性“listings” - AttributeError at /addtowatchlist/5: 'QuerySet' object has no attribute 'listings' AttributeError: 'QuerySet' 对象没有属性 'tags' - AttributeError: 'QuerySet' object has no attribute 'tags' AttributeError: 'QuerySet' object 没有属性 'product' 错误 - AttributeError: 'QuerySet' object has no attribute 'product' ERROR AttributeError:“ QuerySet”对象没有属性“ area” - AttributeError: 'QuerySet' object has no attribute 'area' /product/7 'QuerySet' object 处的 AttributeError 没有属性 'category' - AttributeError at /product/7 'QuerySet' object has no attribute 'category' /orders/ 'QuerySet' object 处的 AttributeError 没有属性 'orderitem - AttributeError at /orders/ 'QuerySet' object has no attribute 'orderitem
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM