【发布时间】:2019-08-14 15:10:31
【问题描述】:
谁能解释一下我在下面的 shell 输出中看到的内容:
import test/models.py
biz_area = BusinessArea.objects.filter(business_area_manager=user)
dprint(biz_area)
[{'_state': <django.db.models.base.ModelState object at 0x3726890>,
'business_area_id': Decimal('42'),
'business_area_manager': Decimal('999'),
'business_area_name': u'group 1',
'inactive': u'N'}]
biz_area.business_area_id
Traceback (most recent call last):
File "<<console>console>", line 1, in <<module>module>
AttributeError: 'QuerySet' object has no attribute 'business_area_id'
所以,python 说 biz_area 查询集没有 'business_area_id' 属性,而漂亮打印的对象列表显示它确实具有这样的属性。有人可以在这里把我放在正确的轨道上吗,因为这让我有些困惑......
【问题讨论】:
-
biz_area['business_area_id']呢? -
@Matthias 不起作用,因为
biz_area是对象的集合 -
你当然是对的。我应该用我的其他眼镜来看看这个问题......