Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Getting a raw SQL query from QuerySet

Tags:

python

django

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?

like image 211
Gill Bates Avatar asked Jun 30 '26 19:06

Gill Bates


1 Answers

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

str(Something.objects.all().query)
like image 75
Alp Avatar answered Jul 03 '26 10:07

Alp