Custom Search

Monday, March 9, 2015

How to Get the SQL Query from Django QuerySet

1)
Open django shell
#python manage.py shell

2)
Import the model class
>>> from bla.models import Building

3)
Print the SQL query
>>> print Building.objects.all().query
OR
>>> Building.objects.all().query.__str__()




1 comment:

  1. How do you add a where command in Django like select this from this wherer a = b or something like that

    ReplyDelete