In Django 1.1 I was able to produce the SQL used by a QuerySet
with this notation:
QuerySet.query.as_sql()
In Django 1.2, this raises as AttributeError
.
Anyone know the Django 1.2 equivalent of that method?
Thanks
You get a QuerySet by using your model's Manager . Each model has at least one Manager , and it's called objects by default. Access it directly via the model class, like so: >>> Blog.objects <django.db.models.manager.Manager object at ...> >>> b = Blog(name='Foo', tagline='Bar') >>> b.objects Traceback: ...
A QuerySet is a collection of data from a database. A QuerySet is built up as a list of objects. QuerySets makes it easier to get the data you actually need, by allowing you to filter and order the data.
Django allows using SQL subqueries.
The raw() manager method can be used to perform raw SQL queries that return model instances: Manager. raw (raw_query, params=(), translations=None) This method takes a raw SQL query, executes it, and returns a django.
In Django 1.1, QuerySet.query
returned a BaseQuery
object, now it returns a Query
objects. The query object has a __str__
method defined that returns the SQL.
as answered in In django 1.2.1 how can I get something like the old .as_sql?
it's just:
print QuerySet.query
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With