0

How do I print to the terminal the query used by a specific line of python code? see below

notifications = user.get_notifications(max_id=max_id, types=types).order_by('-created')[:count]
Frank Castle
  • 335
  • 3
  • 23
  • 2
    Welcome back to Stack Overflow. As a refresher, please read [ask] and note well that this is **not a discussion forum**. [Please try](https://meta.stackoverflow.com/questions/261592) to look for existing answers before asking - finding the linked duplicate was as easy as putting `[django] print query` into the site search - and please do not make "thanks" comments - instead, see the advice at https://stackoverflow.com/help/someone-answers. – Karl Knechtel Aug 27 '22 at 11:36

1 Answers1

2

You can print the query by adding:

.query

after your call.

It'll look like this:

user.get_notifications(max_id=max_id, types=types).order_by('-created')[:count].query

If you're doing this in the py manage.py shell, don't forget to print() it out. Otherwise it will show a memory address.

nigel239
  • 1,485
  • 1
  • 3
  • 23