/Django-ORM-Mastery-DJ003

Master the Django ORM - Object-Relational Mapper. Learn to use the Django ORM in your Django applications.

Primary LanguagePythonMIT LicenseMIT

veryacademy

Django ORM Mastery Series

Master the Django ORM - Object-Relational Mapper
The Django ORM’s main goal is to facilitate data transfer between a relational database, MySQL/Postgres and many others and the Django application model. The most convenient aspect of the ORM is that it automates this transmission, such that the developer need not learn or write any SQL. This is a powerful features of Django that enables rapid development of applications developed with the Django framework.

Please join our active, growing community:
Website (Coming Soon) | Twitter | YouTube

PayPal this

Aims of this course

The aims of this course is to:

  • learn how to build applications using the Django framework ORM

Course Introduction

The Django ORM mastery Series is designed for students who wants to learn the Django Framework ORM in more detail than that is normally presented on Django courses. Therefore, this course is a great way to start expanding your knowledge of Django development. We start from a beginners level slowly moving into more advanced topics. I have tried to design this course to be modular so that you could also focus in on particular subjects, tutorials or aspects of the Django ORM should you prefer this mode of learning. Django as a powerful framework makes it easy to interact with database with the Django ORM. This allows you to directly map your object-oriented models to database table structures and in doing so also builds the data and table relationships.

On this course you will be taught a wide range of skills, here are a few topics that we will be learning:

  • Filter and exclude methods
  • F and Q objects
  • django-debug-toolbar
  • Annotations and aggregations

Tutorials

The free tutorials, can be found here on our YouTube channel. If you find the series of tutorials valuable, please consider donating to help us create and grow our tutorial library.

Prerequisites

  • Install Python onto your PC/Laptop
  • Optional - Visual Studio Code Editor
  • Tutorials use Windows OS (you can use other OS but it might require additional steps not detailed in the tutorials)
  • Ideally you would have some knowledge of creating a basic Django application

Who is this course for

This course tries to cater for many types of learners:

  • new developers,
  • not so new developers,
  • degree students,
  • Everyone else who is looking to learn Django in more depth

Course Content

Level 1 - What is the Django ORM?
A quick overview and demystification of the basics concepts of the Django ORM. The Django ORM is a core feature which we will be exploring in this tutorial series. You will get to know more about making queries and how that translates to SQL.

Link to Tutorial https://youtu.be/iQF6pln3Gog
Level 1 - How to perform an OR query on a database - including Q objects [Repo:2]
The Django ORM series covers a range of common functions that you will perform on a database with Django. In this tutorial we take a look at creating OR queries both in native Django statements and using Q objects. In addition we take a look at the SQL that powers the queries and look to see how we can see the performance of our queries.

Link to Tutorial https://youtu.be/XbOUjyC--Ao
Level 1 - How to perform an AND query on a database - including Q objects [Repo:3]
The Django ORM series covers a range of common functions that you will perform on a database with Django. In this tutorial we take a look at creating AND queries both in native Django statements and using Q objects. In addition we take a look at the SQL that powers the queries and look to see how we can see the performance of our queries.

Link to Tutorial https://youtu.be/yuRisebNnvU
Level 1 - How to perform a UNION query on a database [Repo:4]
The Django ORM series covers a range of common functions that you will perform on a database with Django. In this tutorial we take a look at creating UNION queries on multiple select statements. In addition we take a look at the SQL that powers the queries and look to see how we can see the performance of our queries.

Link to Tutorial https://youtu.be/_kvvHXS-OZs
Level 1 - How to perform a NOT query on a database - including Q Objects [Repo:5]
The Django ORM series covers a range of common functions that you will perform on a database with Django. In this tutorial we take a look at creating NOT queries or Django exclude as it is known on multiple select statements. We look at a basic example of exclude as well as using Q objects to build a NOT query. In addition we take a look at the SQL that powers the queries and look to see how we can see the performance of our queries.

Link to Tutorial https://youtu.be/o2ZgwV8R2Rk
Level 1 - Select and Output individual fields [Repo:6]
The Django ORM series covers a range of common functions that you will perform on a database with Django. In this tutorial we take a look at how to select individual fields from a database and output the data onto a template.

Link to Tutorial https://youtu.be/fdkgcZHA0Ew
Level 1 - Performing raw SQL queries [Repo:7]
The Django ORM series covers a range of common functions that you will perform on a database with Django. In this tutorial we introduce the idea of running your own SQL queries, thus bypassing some of the Django ORM features. This is an introductory guide to help you get start with the general concepts and structure of building raw SQL queries.

Link to Tutorial https://youtu.be/iWDvsMOngxk
Level 1 - Performing raw SQL queries without the ORM [Repo:8]
The Django ORM series covers a range of common functions that you will perform on a database with Django. In this tutorial we introduce the idea of running your own SQL queries, thus bypassing the Django ORM features. This is an introductory guide to help you get start with the general concepts and structure of building SQL queries outside of the Django ORM.

Link to Tutorial https://youtu.be/_TtBxvYwoHY
Level 1 - Django Model Inheritance Options Introduction
The Django ORM series covers a range of common functions that you will perform on a database with Django. In this tutorial we introduce the idea of model inheritance using 3 options that Django provides, Abstract models, Multi-table model inheritance and Proxy models. I give you an overview of each and provide a small example of how to use each type of inheritance option.

Link to Tutorial https://youtu.be/4Xag2FzmN60
Level 1 - Towards SQL Optimization - Django Debug Toolbar Package
Thinking more serious about Python Django means understanding a little more about the performance of our django application. As you might imagine there are many tools and methods to measure performance. Moving into that direction the django-debug-toolbar give us provide some useful information to help us start thinking about database/SQL optimizations.

This level of abstraction the ORM provides (although it does a great job) it can cloud our understanding the performance of our application. And as better performance can convert to lower running costs – its an important aspect of our development we need to know more about.

Starting your journey to database optimization, we need to understand what is happening behind the scenes or more importantly monitor SQL performance. If you have seen the other tutorials in this series we already know that we can collect information about SQL queries that be being executed. In this tutorial, although there are many various ways to log SQL queries, here we take a look at the package django-debug-toolbar – which as you will see provides more than just SQL information. Overall, it provides us some great insights into our application.

Link to Tutorial https://youtu.be/riBTlU6iMc4

Level 1 - First Look: Transaction Atomicity
Django’s default behaviour is to run in autocommit mode, By default each query is immediately committed to the database, each SQL query gets wrapped in its own transaction and a transaction is automatically committed or rolled back.

A transaction is a sequence of one or more SQL operations that are treated as a unit. All operations should be executed successfully in order to call the transaction successful. Transactions ideally have four properties, commonly known as ACID. This is a standard set of properties aimed to guarantee database transactions are processed reliably which is especially concerned with how a database recovers from any failure.

Atomicity is the defining property of database transactions. Atomic require us to create a block of code within which the atomicity on the database is guaranteed.

Link to Tutorial https://youtu.be/BchP5Mn1IYg

Level 2 - Multiple Database Setup [Repo:9]
Python Django multiple database setup example with 3 databases and 2 applications. In this tutorial we look at Django’s support for interacting with multiple databases. This is a beginners introductory example helping us get familiar with setting up multiple databases with Django.

Link to Tutorial https://youtu.be/g-FCzzzjBWo
Level 2 - Python Django Inheritance Optimization Exercise [Repo:20]
In this Python Django tutorial we work through a set of examples to develop a better understanding of Django model inheritance. We try and answer the question of how to design a product table where we may need to have many types of product thus needing to create multiple tables.

Link to Tutorial https://youtu.be/Y4ahqzSs7nI

Community Driven Content

I activity try and promote feedback to taylor courses to your needs and wishes. Here is a list of features requested by community. If you would like to request any other feature not listed here - please visit our YouTube channel and make a comment.

Next Planned Tutorials

  • More coming soon...

Suggestions

  • Please visit our YouTube channel to make suggestions

Contributing

This course welcomes contributions and suggestions. At present, we are not accepting any code contributions. When the tutorials have finished the project will be open to welcome code contributions. If you find any errors or have trouble with any of our code - please get in contact with us through our YouTube channel.

Instructor

Zander, the founder of Very Academy has over 20 years of development and educational lecturing experience. He is now focused on developing free technical courses and resources on a range of subjects.

License

MIT License