[英]TypeError: int() argument must be a string or a number, not 'dict'
I'm try to get all the building structures with the hazard type "High". 我尝试获取所有危害类型为“高”的建筑结构。 I have this following query:
我有以下查询:
>>> reference = FloodHazard.objects.filter(hazard='High')
>>> ids = reference.values('id')
>>> for id in ids:
... getgeom = FloodHazard.objects.get(id=id).geom
... getbldg = BuildingStructure.objects.filter(geom__intersects=getgeom).value_list('id')
Traceback (most recent call last):
File "<console>", line 3, in <module>
File "C:\Python27\lib\site-packages\django\db\models\manager.py", line 151, in get
return self.get_queryset().get(*args, **kwargs)
File "C:\Python27\lib\site-packages\django\db\models\query.py", line 298, in get
clone = self.filter(*args, **kwargs)
File "C:\Python27\lib\site-packages\django\db\models\query.py", line 590, in filter
return self._filter_or_exclude(False, *args, **kwargs)
File "C:\Python27\lib\site-packages\django\db\models\query.py", line 608, in _filter_or_exclude
clone.query.add_q(Q(*args, **kwargs))
File "C:\Python27\lib\site-packages\django\db\models\sql\query.py", line 1198, in add_q
clause = self._add_q(where_part, used_aliases)
File "C:\Python27\lib\site-packages\django\db\models\sql\query.py", line 1234, in _add_q
current_negated=current_negated)
File "C:\Python27\lib\site-packages\django\db\models\sql\query.py", line 1125, in build_filter
clause.add(constraint, AND)
File "C:\Python27\lib\site-packages\django\utils\tree.py", line 104, in add
data = self._prepare_data(data)
File "C:\Python27\lib\site-packages\django\contrib\gis\db\models\sql\where.py", line 42, in _prepare_data
return super(GeoWhereNode, self)._prepare_data(data)
File "C:\Python27\lib\site-packages\django\db\models\sql\where.py", line 79, in _prepare_data
value = obj.prepare(lookup_type, value)
File "C:\Python27\lib\site-packages\django\db\models\sql\where.py", line 352, in prepare
return self.field.get_prep_lookup(lookup_type, value)
File "C:\Python27\lib\site-packages\django\db\models\fields\__init__.py", line 369, in get_prep_lookup
return self.get_prep_value(value)
File "C:\Python27\lib\site-packages\django\db\models\fields\__init__.py", line 613, in get_prep_value
return int(value)
TypeError: int() argument must be a string or a number, not 'dict' So, how do I get the IDs of all the FloodHazard with hazard "high"? TypeError:int()参数必须是字符串或数字,而不是'dict'。那么,如何获得危险为“高”的所有FloodHazard的ID? I understand error but when I try
reference.id
it returns AttributeError: 'GeoQuerySet' object has no attribute 'id'
. 我理解错误,但是当我尝试
reference.id
它返回AttributeError: 'GeoQuerySet' object has no attribute 'id'
。
values()
returns a list of dicts. values()
返回字典列表。 You should use the values_list()
method instead: 您应该改用
values_list()
方法:
ids = reference.values_list('id', flat=True)
Use: 采用:
evntids=EventMember.objects.values('event_id').distinct()
output in dictionary form: 以字典形式输出:
QuerySet [{'event_id': 1}, {'event_id': 2}]
Use: 采用:
evntids=EventMember.objects.values_list('event_id',flat=True).distinct()
output in int form: 以int形式输出:
QuerySet [1, 2]
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.