3.6.1 Basic Database Interaction via Models

We can interact quite powerfully with Django’s ORM in the Python interpreter. This is useful not only because it will help us learn Django on the fly but also because it is a tool we will continue to use throughout our careers in Django. Using the interpreter to test queries as you write them can help speed the development process.

Rather than invoke Python and then import the necessary Django tools, Django provides a shortcut. We can invoke ./manage.py shell, which runs the Python interpreter (or IPython, if you have it installed) and fetches the bare minimum for Django to work. From there we can begin loading in our own project code, as shown in Example 3.39.

Example 3.39: Python Interpreter Code ...

Get Django Unleashed now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.