Gill Bates
Gill Bates

Reputation: 15127

Getting a raw SQL query from QuerySet

I have simple model like this:

class Something(models.Model):
    data = models.CharField(max_length=200)

And when Im performing this:

Something.objects.all().query

I get this:

<django.db.models.sql.query.Query object at 0xa57b9ec>

What is it mean? Im using newest version of Django (1.5.2). In older versions .query was returned a string with the SQL query. How can I get it in new version?

Upvotes: 3

Views: 2483

Answers (1)

Alp
Alp

Reputation: 29739

As we found out in the comments, that's your answer:

str(Something.objects.all().query)

Upvotes: 5

Related Questions