Django ORM - QuerySet Filtering and Lookups / Ordering and Slicing QuerySets

In this video, we'll dive into many topics, including how to filter QuerySets of records in Django, using the filter() and exclude() functions, and how to pass lookups such as "gt" (greater than), "lt" (less than), "range", "in", and "startswith". We will see how these lookups translate to the underlying SQL, for example: "in" = IN operator in SQL "range" = BETWEEN operator etc We will also look at how to order QuerySets in Django, using the order_by() function, and using the model Meta class to define a default ordering. We'll also see how to apply the Lower database function in order to retrieve a case-insensitive ordering over character fields. We'll see how to index/slice into QuerySets, how to use the get() function to retrieve a model, the exists() function to check for the existence of records in a QuerySet, and the earliest() and latest() functions to retrieve the earliest and latest objects using a date/datetime field. Starter Code: https://github.com/bugbytes-io/django... ๐Ÿ“Œ ๐—–๐—ต๐—ฎ๐—ฝ๐˜๐—ฒ๐—ฟ๐˜€: 00:00 Intro 01:09 Setup and management command 04:51 Filtering QuerySets with filter() method 07:39 Getting a single model back with the get() method 10:03 Checking if QuerySet contains records with exists() method 10:38 Multiple AND conditions with the filter() method 13:24 Filtering QuerySets with the โ€œinโ€ lookup 15:17 Filtering QuerySets with the exclude() method 17:52 Filtering QuerySets with โ€œltโ€ and โ€œgtโ€ lookups 21:39 Filtering QuerySets with the range lookup 22:52 Ordering QuerySets with the order_by() method 26:15 Case-insensitive orderings with the Lower database function 28:47 Ordering by date & datetime fields 29:25 Indexing and Slicing into QuerySets - LIMIT and OFFSET SQL statements 31:26 Adding โ€˜orderingโ€™ field to model Meta class for default ordering 33:23 ORM earliest() and latest() functions 35:01 Meta class get_latest_by field 35:55 Filtering by foreign key values in Django โ˜•๏ธ ๐—•๐˜‚๐˜† ๐—บ๐—ฒ ๐—ฎ ๐—ฐ๐—ผ๐—ณ๐—ณ๐—ฒ๐—ฒ: To support the channel and encourage new videos, please consider buying me a coffee here: https://ko-fi.com/bugbytes โ–ถ๏ธ Full Playlist: ย ย ย โ€ขย Djangoย ORMย Deepย Diveย ย  ๐—ฆ๐—ผ๐—ฐ๐—ถ๐—ฎ๐—น ๐— ๐—ฒ๐—ฑ๐—ถ๐—ฎ: ๐Ÿ“– Blog: https://bugbytes.io/posts/ ๐Ÿ‘พ Github: https://github.com/bugbytes-io/django... ๐Ÿ“š ๐—™๐˜‚๐—ฟ๐˜๐—ต๐—ฒ๐—ฟ ๐—ฟ๐—ฒ๐—ฎ๐—ฑ๐—ถ๐—ป๐—ด ๐—ฎ๐—ป๐—ฑ ๐—ถ๐—ป๐—ณ๐—ผ๐—ฟ๐—บ๐—ฎ๐˜๐—ถ๐—ผ๐—ป: Github: https://github.com/bugbytes-io/django... Django filter() function: https://docs.djangoproject.com/en/4.2... Django get() function: https://docs.djangoproject.com/en/4.2... Field Lookups: https://docs.djangoproject.com/en/4.2... Django Lower function: https://docs.djangoproject.com/en/4.2... #python #django #webdevelopment #database #sql

Django Query Optimization / select_related & prefetch_related / django-debug-toolbar / N+1 Problem
โ–ถ๏ธŽ

Django Query Optimization / select_related & prefetch_related / django-debug-toolbar / N+1 Problem

Django ORM - Updating and Deleting QuerySets / ForeignKey on_delete behaviour
โ–ถ๏ธŽ

Django ORM - Updating and Deleting QuerySets / ForeignKey on_delete behaviour

Why Your SQL Query Is Slow (And How to Actually Fix It)
โ–ถ๏ธŽ

Why Your SQL Query Is Slow (And How to Actually Fix It)

Django Model Properties & Methods | @property decorator | get_absolute_url() method
โ–ถ๏ธŽ

Django Model Properties & Methods | @property decorator | get_absolute_url() method

Django Aggregation & Annotation / values() and values_list() functions
โ–ถ๏ธŽ

Django Aggregation & Annotation / values() and values_list() functions

Django ORM - Querying and Creating Records / Working with Foreign Keys
โ–ถ๏ธŽ

Django ORM - Querying and Creating Records / Working with Foreign Keys

Custom Model Managers and QuerySets: Graduating from Django Beginner to ORM Master with Josh Thomas
โ–ถ๏ธŽ

Custom Model Managers and QuerySets: Graduating from Django Beginner to ORM Master with Josh Thomas

The data black hole at the center of AI
โ–ถ๏ธŽ

The data black hole at the center of AI

How Instagram Scaled Postgres to 2 Billion Users
โ–ถ๏ธŽ

How Instagram Scaled Postgres to 2 Billion Users

Beginner to T-SQL [Full Course]
โ–ถ๏ธŽ

Beginner to T-SQL [Full Course]

But what is quantum computing?  (Grover's Algorithm)
โ–ถ๏ธŽ

But what is quantum computing? (Grover's Algorithm)

PostgreSQL Crash Course - Beginner Tutorial
โ–ถ๏ธŽ

PostgreSQL Crash Course - Beginner Tutorial

Django - select_for_update() function / Locking Database Rows
โ–ถ๏ธŽ

Django - select_for_update() function / Locking Database Rows

Django - F Expressions for database-level operations
โ–ถ๏ธŽ

Django - F Expressions for database-level operations

Django - Multiple Databases | inspectdb command | Database Routers
โ–ถ๏ธŽ

Django - Multiple Databases | inspectdb command | Database Routers

Learn Basic SQL in 15 Minutes | Business Intelligence For Beginners | SQL Tutorial For Beginners 1/3
โ–ถ๏ธŽ

Learn Basic SQL in 15 Minutes | Business Intelligence For Beginners | SQL Tutorial For Beginners 1/3

Web Scraping Using Python For Beginners and File Handling in Python | Python Web Scraping
โ–ถ๏ธŽ

Web Scraping Using Python For Beginners and File Handling in Python | Python Web Scraping

How to make 3D Games in Godot
โ–ถ๏ธŽ

How to make 3D Games in Godot

Django - COALESCE Function and Handling NULL Values in the Database
โ–ถ๏ธŽ

Django - COALESCE Function and Handling NULL Values in the Database

Something is jamming GPS over Europe. Here's what we found
โ–ถ๏ธŽ

Something is jamming GPS over Europe. Here's what we found