Help!
I have two objects that i have created using different techniques in django;
>>> from django.contrib.contenttypes.models import ContentType
>>> from myproject.models import Building
Method A
>>> content_type = ContentType.objects.get(app_label='myproject', model='Building')
>>> content_class = content_type.model_class()
>>> content_query = content_class.objects.raw("Select * from pms_building where name like '%build%' ")
>>> type(content_query)
<class 'django.db.models.query.RawQuerySet'>
>>> content_query[0]
# error ....
# Attribute: 'str' object has no attribute 'items'
Method B
>>> bld = Building.objects.raw("Select * from pms_building where name like '%build%' ")
>>> type(bld)
<class 'django.db.models.query.RawQuerySet'>
>>>bld[0]
<Building: Building A>
My question is why are the two objects of the same type behaving differently?
Gath
The SQL query is only executed when you call
content_query[0], so the query will fail at that point if something is wrong withcontent_classfor example. At least I noticed that you forgot theobjectsfrom the first line:EDIT: I get the “‘str’ object has no attribute ‘items'” error when %-marks are incorrectly interpreted. This fixed it for me: