HTMX + Django: Modern Python Web Apps, Hold the JavaScript Transcripts
Chapter: Feature 2: Active search
Lecture: Django Q objects

Login or purchase this course to watch this video and the rest of the course contents.
0:00 Before I start writing the view, a quick summary of Django QObjects in case they're not fresh in your mind.
0:07 A QObject is a way of creating queries that are more complex than what you can do with the filter method all on its own.
0:15 The top example here shows two QObjects ANDed together. Each QObject is created using the same kind of arguments you would put in a call to filter.
0:26 by ending a cue with title and another with author, I'm creating the same result as putting those both in a filter. To run the cue or a composed cue,
0:37 you simply pass it into the filter call. This kind of mechanism can be really helpful if you're trying to create dynamic clauses to queries
0:45 that have differing numbers of terms based on some business logic. My most common use of these is actually simpler than that though.
0:54 I use it when I need to OR terms together instead of ANDing them. The example at the bottom here does that.
1:01 Here, videos with the title Indie or the author Romaine will be found in the results. Momentarily, I'll use QObjects to search our videos
1:11 in the search view. Let's go write some code.


Talk Python's Mastodon Michael Kennedy's Mastodon