๐ป Models & Queries ๐ป
Posted on Sep 7th, 2022
๐๏ธ Todayโs Topics
- The woes of deployment and what to do about them
- Django managers, lookups, and querysets
- Using the Django shell to test out your models and make queries
๐ฏ Project: Continue Building Habit Tracker
Today your models should be done, so you can begin building out the urls, views, and templates you will need. Before you write the code, plan for what you will need. A good way to do this is to sketch out what your user will see.
There are examples for a lot of what you need to do in the Django Recipes codebase but you will have to adapt them to your Habit Tracker use cases.
๐ Resources
Models
- List of all Django Reference content related to Models
- Donโt forget! Django Best Practices: Custom User Model
- Django Docs: Saving Model Instances
Managers and QuerySets
Queries
You can think of queries as talking to the database. To support all our CRUD actions, we need to be able to create, read, update, and delete objects from the database. Django has a built-in library (the Django ORM) that lets us do all that.
- Django Queries: Retrieving Objects
- Django Queries: Field lookups
- Django Queries: Lookups that span relationships
- Django Queries: Lookups with Related objects
๐ EXTRA/TMI
Links in this section are really more information than you need right now, but itโs relevant and interesting. Things included here are good to know but ok to save for later.
- What is SQL?
- SQL Basics: Learn X in Y minutes -> this is a helpful reference for SQL syntax when you run into it. You do not need to write SQL for Django because the Django ORM does it for you, and it does it well. The Django docs often illustrate queries made by the ORM using SQL syntax, however, and you will find it helpful in your job to know the basics.