🚀 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 🚀
More Relevant Posts
-
🚀 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 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
-
🚀 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
-
🚀 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
-
🚀 Django Day 32 — Understanding Migrations ⚙️🧩 Today I learnt about one of Django’s key database features — Migrations. But before that, I discovered that the code I wrote yesterday inside the models.py file wasn’t being recognized by Django 😅. After checking, I realized I forgot to add my app to the INSTALLED_APPS section in the settings.py file. Once I fixed that, everything started working properly. Migrations are basically a way for Django to define and execute steps that modify or update the database whenever I make changes in my models. So whenever I create or edit a model, I need to create and run migrations to apply those changes to the actual database. I created a migration by running the command “python manage.py makemigrations”, and immediately, a new file appeared in the migrations folder called “0001_initial.py”. This file contained some auto-generated code that describes the operations Django should perform on the database. Next, I ran another command, “python manage.py migrate”, which told Django to go through all migration files (including the built-in apps) and execute them. This process created a new database file named “db.sqlite3” — although I can’t open it directly because it’s stored in a binary form. Today’s session helped me understand how Django connects my Python-defined models to a real database using migrations — making everything feel more automated and professional 💻🗄️ #Django #Python #Migrations #SQLite #Database #BackendDevelopment #WebDevelopment #100DaysOfCode #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
-
-
🚀 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
-
-
🚀 Successfully Connected My Django Project to a Database & Added Data! I’m super excited to share my latest progress in Django! 🌱 Today, I successfully connected my Django project to a database and added real data using Django’s Model layer — one of the most powerful components of its MVT (Model-View-Template) architecture. 🧩 Understanding the Concept In Django, the Model acts as the foundation for how data is structured and managed. It represents a table in the database, and each attribute inside a model becomes a column in that table. Instead of writing raw SQL queries, Django uses an Object Relational Mapper (ORM), which allows developers to interact with the database using simple Python code. This makes Django both beginner-friendly and highly scalable for large projects. 💡 What I Learned Today Here’s what I explored and implemented step by step: ✅ Created a new model in models.py to define database structure ✅ Used commands like makemigrations and migrate to create and sync tables ✅ Added and retrieved data using Django’s ORM instead of SQL queries ✅ Accessed the Django Admin Dashboard to visually confirm the entries ⚙️ Key Commands Used python manage.py makemigrations # Prepares migration files python manage.py migrate # Applies changes to the database python manage.py createsuperuser # Creates admin login credentials python manage.py runserver # Runs the local development server 🎯 Key Takeaways ✨ Django models make it effortless to define, create, and manipulate databases. ✨ ORM eliminates the need for SQL — everything is handled in Pythonic style. ✨ The admin panel makes database management easy and visually accessible. This was a great experience to see how code turns into structured data — stored, retrieved, and managed efficiently with Django. 🔥 📊 Outcome ✅ Database connection established ✅ Models created & migrated successfully ✅ Data added and displayed in the Admin Panel ✅ Fully functioning backend ready to scale 🎥 Demo Video & Project Code: 🔗 GitHub Repository : https://lnkd.in/ebJZWs9j I’ll keep sharing my Django progress every day as I continue building real-world applications using Django + Django REST Framework. 💻 Special Thanks To Manivardhan Jakka and 10000 Coders #Django #Python #BackendDevelopment #WebDevelopment #LearningInPublic #100DaysOfCode #DjangoModels #DatabaseIntegration #SoftwareEngineering #DjangoORM #DevelopersJourney
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! graphical user interface image dedo related to this caption and make post for linkdin
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
Explore related topics
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