🚀 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 🚀💡
More Relevant Posts
-
🚀 *Day 8 of #30DaysOfDjango – Models & ORM Magic! 🧠💾* Hey Django Ninjas 👋 Yesterday, we mastered *Template Inheritance* and made our front-end cleaner and smarter! 🎨 But websites aren’t just about beautiful pages — they need *data* to come alive! ⚡ Today, we dive into Django’s powerhouse: *Models & ORM (Object-Relational Mapping)* 🧩 💡 *What’s a Model?* It’s the blueprint of your database — defining the structure of your data (like tables). 💡 *What’s ORM?* ORM lets you interact with your database using *Python code* instead of raw SQL. No messy queries — just clean, readable Django syntax! 😎 🔥 *Example:* python from django.db import models class Student(models.Model): name = models.CharField(max_length=100) age = models.IntegerField() course = models.CharField(max_length=50) ⚙ *Run the Magic Commands:* python manage.py makemigrations python manage.py migrate Boom 💥 — your database is ready to roll! 🎯 *Next up (📅 Day 9):* We’ll bring data to life in your web pages with **Django Admin & QuerySets! graphical user interface image dedo related to this caption and make post for linkdin
To view or add a comment, sign in
-
-
🚀 Django Day 37 — Using OR Conditions + Understanding Query Performance ⚡🔍📚 Today, I explored something new and very powerful in Django’s querying system — the “OR” condition. Normally, when filtering database records, Django uses AND by default, but sometimes I need to find data that meets one condition OR another — and that’s where the OR operator becomes really helpful 💡✨ To use the OR condition, I had to import Q from Django like this: from django.db.models import Q The Q object allows me to combine multiple conditions using the | (OR) operator so I can search for entries that match either one condition or the other. For example: • books written by a certain author OR • books with a certain rating This makes filtering faster, more flexible, and way more accurate when searching for specific items 🔎📘 After learning that, I also touched on something very important — Query Performance ⚙️📊 Query Performance is all about how efficiently the database retrieves your data. In simple terms, it teaches you how to: • avoid unnecessary queries • reduce repeated lookups • write filters that are faster • and make sure your database isn’t overloaded Basically, it's making sure that when your app grows bigger with more data, everything still runs smoothly without slowing down ⚡💼 Today was all about writing smarter queries and understanding how Django handles data behind the scenes.💪🔥 #Django #Python #Database #QObjects #ORConditions #Filtering #QueryPerformance #BackendDev #WebDevelopment #100DaysOfCode #LexissLearns 🚀💡
To view or add a comment, sign in
-
🚀 Day 8 of #30DaysOfDjango – Models & ORM Magic! 🧠💾 Hey Django Ninjas 👋 Yesterday, we mastered *Template Inheritance* and made our front-end cleaner and smarter! 🎨 But websites aren’t just about beautiful pages — they need *data* to come alive! ⚡ Today, we dive into Django’s powerhouse: *Models & ORM (Object-Relational Mapping) 🧩 💡 What’s a Model? It’s the blueprint of your database — defining the structure of your data (like tables). 💡 What’s ORM? ORM lets you interact with your database using *Python code* instead of raw SQL. No messy queries — just clean, readable Django syntax! 😎 🔥 Example: python from django.db import models class Student(models.Model): name = models.CharField(max_length=100) age = models.IntegerField() course = models.CharField(max_length=50) ⚙ Run the Magic Commands: python manage.py makemigrations python manage.py migrate Boom 💥 — your database is ready to roll! 🎯 Next up (📅 Day 9): We’ll bring data to life in your web pages with Django Admin & QuerySets! #Django #30DaysOfDjango #PythonDeveloper #WebDevelopment #DjangoModels #ORM #DatabaseDesign #BackendDevelopment #LearnToCode #PythonProgramming #TechWithPython #BuildWithDjango #CodeNewbie #DeveloperCommunity #CleanCode #WebDev
To view or add a comment, sign in
-
-
🚀 Django Day 34 — Updating Models & Running New Migrations ⚙️📚 After learning how to insert and view data in the database yesterday, today I focused on updating my models by adding more details (columns) to the database tables — such as author and is_bestselling fields 🧩✨. To apply these updates, I first created a new migration by running: “python manage.py makemigrations” ⚙️ However, it didn’t work at first 😅 — Django prompted me to provide a default value for the new fields I added. This happened because the database already contained data from before, and Django didn’t know what values to assign to the new columns. So, I fixed the issue by adding a default value and setting null=True in my model. Then I re-ran the command, and Django successfully generated a new migration file named something like “0002_....py” ✅ Next, I executed the migration using: “python manage.py migrate” 🖥️ This applied the changes to the database, officially updating the table structure with my new model fields 🎯 Finally, I opened the Django shell again using: “python manage.py shell” — to confirm that everything worked perfectly and my changes were now reflected in the database 💪📊 There’s a video below showing how the entire process looks like now 🎥 #Django #Python #Database #Migrations #Models #SQLite #BackendDevelopment #WebDevelopment #100DaysOfCode #LexissLearns 🚀💡
To view or add a comment, sign in
-
🚀 Django Day 29 — Understanding Data Models & Types of Data Today marks the beginning of a new phase in my Django journey — working with data, databases, and models! 💻 For the next couple of days, I’ll be focusing on how Django handles and stores data properly, because we definitely need a real database for our blog posts instead of the handwritten data I’ve been using 😅. Before diving into actual models, I learnt about the different types of data — not the official ones, but simplified categories my tutor created for better understanding 👇 i.) Temporary Data ⚡ — This type of data is short-lived and not needed later. It’s used immediately and then lost. For example, user inputs or a selected blog post that disappears when you refresh the page. ii.) Semi-Persistent Data 🔄 — This data stays for a while but can be lost or recreated. For example, user authentication status — like when you log in to your bank app and after 15 minutes of inactivity, it logs you out and you have to re-enter your password again. iii.) Persistent Data 💾 — This is long-term data that must not be lost, as it’s essential for the system. For example, bank transactions, customer orders, or blog posts — all of which are stored permanently in a database. Understanding these types of data helps me see where Django models come in — they help manage persistent data automatically and make it easy to store, retrieve, and display information across the project 🙌. #Django #Python #Databases #Models #BackendDevelopment #100DaysOfCode #LearningInPublic #LexissLearns 🚀
To view or add a comment, sign in
-
🚀 Django Day 35 — Understanding BLANK vs NULL + Updating & Deleting Data 🔍📚 Yesterday, while updating my models, I had to set null=True for one of the new fields. Today, I discovered that there’s also blank=True, so I decided to properly understand the difference between the two 🧠✨ Here’s what I learnt: 🔹 null=True This tells Django that if no value is provided, the database should store a NULL value. It affects the database level. 🔹 blank=True This tells Django that this field is allowed to be empty when submitting data through a form. It affects form validation, not the database. After clearing that up, I practised how to update and delete data directly from the Django shell. I assigned an object to a variable, updated its fields using dot notation, and then saved it ✔️. I also tested deleting a record to see how it works. All of this was done inside the interactive console opened with: “python manage.py shell” 🖥️⚡ Not gonna lie, today wasn’t my smoothest day in the terminal 😅— small mistakes kept slowing me down and stressing me out. But like I always say: ✨ Consistency and resilience are what turn frustration into mastery. Keep pushing. 💪🔥 There’s a video below showing some parts of today’s work 🎥👇 #Django #Python #Models #BlankVsNull #Database #Shell #BackendDev #WebDevelopment #LearningJourney #100DaysOfCode #LexissLearns 🚀📘
To view or add a comment, sign in
-
🚀 Django Day 31 — Understanding SQL & Discovering Django Models 🧠📚 Since I’ve already chosen SQL as my approach for handling databases, today I decided to dive deeper into how SQL actually works and how it connects with Django 💻. The general process of working with SQL involves three key steps: i.) Creating tables and setting their schema (done once the database is initialized). ii.) Inserting data into those tables — adding records that represent real information. iii.) Retrieving data when needed — using SQL queries to fetch or manipulate stored records 🔍. While learning this, I discovered that Django makes this process much easier through a powerful built-in feature called Models 🧩. Models allow me to describe my data structure (like a table schema) directly in Python code — and Django automatically translates it into SQL behind the scenes. This means I can define how my data should look, and Django handles all the complex SQL for me 😎. To put this into practice, I created a new project named “Book_Store”, and within it, an app called “book_outlet”. Inside the app’s built-in models.py file, I started defining my first model. In the short video below, you’ll see how describing MySQL with python looks like, all thanks to Django’s Model system! ⚙️📖 #Django #Python #SQL #Databases #DjangoModels #BookStoreProject #BackendDevelopment #WebDevelopment #100DaysOfCode #LearningInPublic #LexissLearns 🚀
To view or add a comment, sign in
-
🌟 **Strengthening My Foundations Before Diving Deeper into Django ORM** As part of my ongoing Django learning journey, I’ve reached one of the most powerful features of the framework — the **Object Relational Mapping (ORM)** system. Before moving ahead, I decided to revisit my **SQL fundamentals**, and it has proven to be extremely valuable. A strong understanding of SQL helps in better interpreting how Django ORM interacts with the database, making queries more intuitive and debugging much easier. 🔍 **Key SQL Concepts I am revising:** * Database fundamentals (Tables, Columns, Primary & Foreign Keys) * CRUD operations (SELECT, INSERT, UPDATE, DELETE) * WHERE, ORDER BY, GROUP BY, HAVING * Joins (INNER, LEFT, RIGHT, FULL) * Constraints (UNIQUE, NOT NULL, CHECK) * Aggregate functions (COUNT, SUM, AVG, MIN, MAX) * Indexes & Query Optimization basics * Relationships between tables Revisiting these essentials is helping me build a stronger foundation to fully leverage Django ORM’s capabilities such as model relationships, querysets, filters, lookups, and aggregations. 📘 Excited to continue my learning journey and strengthen my backend development skills. #Django #Python #WebDevelopment #LearningJourney #SQL #DjangoORM #BackendDevelopment #Programming #TechSkills #SoftwareEngineering #DevelopersJourney #Upskilling
To view or add a comment, sign in
-
-
PEP 810: Explicit lazy imports A new PEP has been released for discussion, which suggests adding a new type of imports to Python 3.15. https://lnkd.in/egzvWqGy lazy import json lazy from json import dumps How will it work? The imports will not be loaded until the first time the object is accessed. import sys lazy import json print('json' in sys.modules) # There is no module yet # The download starts here: result = json.dumps({"hello": "world"}) print('json' in sys.modules) # It is now loaded What for? - Load modules faster - Will remove a lot of imports from functions/methods - Allows you to remove if TYPE_CHECKING: import some_module, there were many suggestions for adding an import type construct, example: https://lnkd.in/ePPbhtY7 - Will allow you to solve cyclic imports - Removes the need for a LazyLoader and scary things like https://lnkd.in/eWYrQkMX Implementation Details It is planned to add: - The __lazy_import__ function (analogous to __import__ for importing ) - A special attribute at the module level __lazy_modules__, where lazy imports of the current module will be stored - types.LazyImportType as the type of the new "lazy" module (analogous to `types.moduleType') - sys.lazy_modules for the list of lazy modules globally - sys.set_lazy_imports_filter for global import settings, what? 🤯 - The IMPORT_NAME bytecode will receive a flag indicating whether the import is lazy. - Errors in module names will also be lazy. https://lnkd.in/ezq-Zr3p Funny thing: import* will not be available in lazy mode. # SyntaxError: lazy from ... import * is not allowed lazy from json import * Implementation: https://lnkd.in/eTYqRG4X https://lnkd.in/eeE5nRkv
To view or add a comment, sign in
-
🚀 Django Day 33 — Inserting Data into the Database 🧠💾 Now that I’ve already created and executed my migrations, today I moved on to the exciting part — inserting real data into the database! 😎 To do this, I worked inside my views.py file and then opened the Django shell by running the command: “python manage.py shell” 🖥️ The Django shell is like a special interactive Python environment that allows me to directly interact with my database — creating, saving, and checking data in real time 💬⚙️. Inside the shell, I inserted some data into my database and saved it. Afterwards, I verified that the data was truly stored — and Django showed me the number of entries I had successfully saved. Seeing that confirmation felt amazing because it meant my models and database connection were finally working perfectly together 🔥📊. This marks another major step in building a solid foundation for data handling in Django 💪 The video below shows how data entry looks like #Django #Python #Database #SQLite #DataInsertion #BackendDevelopment #WebDevelopment #100DaysOfCode #LexissLearns 🚀✨
To view or add a comment, sign in
Explore content categories
- Career
- Productivity
- Finance
- Soft Skills & Emotional Intelligence
- Project Management
- Education
- Technology
- Leadership
- Ecommerce
- User Experience
- Recruitment & HR
- Customer Experience
- Real Estate
- Marketing
- Sales
- Retail & Merchandising
- Science
- Supply Chain Management
- Future Of Work
- Consulting
- Writing
- Economics
- Artificial Intelligence
- Employee Experience
- Workplace Trends
- Fundraising
- Networking
- Corporate Social Responsibility
- Negotiation
- Communication
- Engineering
- Hospitality & Tourism
- Business Strategy
- Change Management
- Organizational Culture
- Design
- Innovation
- Event Planning
- Training & Development