Monday, October 31, 2011

Why are my two django objects of the same type behaving differently?

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

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To post to this group, send email to django-users@googlegroups.com.
To unsubscribe from this group, send email to django-users+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

No comments:

Post a Comment