In django 1.2.1 how can I get something like the old .as_sql? [duplicate]
In past versions of django you could construct a queryset and then do .as_sql() on it to find out the final query.
in Django 1.2.1 there is a function ._as_sql() which returns something similar, but not the same.
In past versions:
qs=Model.objects.all()
qs.as_sql() ====>
SELECT `model_table.id`, `model_ta开发者_JS百科ble.name`, `model_table.size` from model_table
This shows me a lot of information.
But if I try it in Django 1.2.1
from django.db import connections
con=connections['default']
qs=Model.objects.all()
qs._as_sql(con) ====>
SELECT U0.`id` from model_table U0
This doesn't show me what fields are actually being selected. I know this information is available somewhere, because in templates, I can still do:
{% for q in sql_queries %}
{{q.time}} - {{q.sql}}
{% endfor %}
which shows me the full version of the query (including the fields selected)
My question is, how can I get this full version within the shell?
qs=Model.objects.all()
qs.query.as_sql()
Should do the job as it is shown here
EDIT:
I just try it and get the same error.
qs=Model.objects.all()
print qs.query
this must give you what you want (:
精彩评论