🚀 Django Day 36 — Using .create() + Filtering & Querying Data 🔍📚 Back in Day 33, I learnt how to insert data into the database by creating an object and then calling the save method. But today, I discovered a much cleaner and faster way to add data — using Django’s create() method ⚡📘 Instead of creating an object first and then saving it, I can simply call the create method like: Book.objects.create(title = “…”, author = “…”, rating = …) This instantly creates and saves the record in one step — no need to call save separately. Super efficient and clean 😎✨ After that, I learnt about filtering and querying, which allow me to search the database much faster and get exactly the data I want. Here’s what they help me do: 🔎 Filtering Filtering allows me to get a specific set of records that match certain conditions. For example, if I want books with rating above 4, or books written by a particular author — I can filter and retrieve only those ones. It’s like telling the database: “I only want items that match this condition.” 🔎 Querying Querying in general means asking the database for information. I can get: • all the books • the first or last book • a specific book by its ID • books that meet multiple conditions And so much more — all by using Django’s query methods. Together, filtering and querying make accessing and organising data super fast and very precise. Instead of scrolling through everything, I can pull out exactly what I need in seconds ⚡📂 Today’s session really showed me how powerful Django’s ORM is — writing Python code but performing deep SQL-level operations under the hood. Love it! 💪🔥 There’s a video below showing me trying out create(), filter(), and different queries 👇🎥 #Django #Python #Database #Queries #Filtering #ORM #BackendDev #WebDevelopment #100DaysOfCode #LearningJourney #LexissLearns 🚀💡

To view or add a comment, sign in

Explore content categories