DEV Community

Rishav Upadhaya
Rishav Upadhaya

Posted on

Day 2: Breaking Down Django Apps & Project Structure

Description
Day 2 of my Django journey, I went deeper into Django by learning how apps fit into a project. If Day 1 was about setting up the basics, today was about organizing those basics into manageable pieces. Here’s how it went:

What Did I Learn?

1) *What Are Django Apps? * Django apps are modular components that handle specific functionalities in your project. Think of them as mini applications within your main project. For example, a blog app, a user authentication app, or a comments system. This modularity makes Django projects scalable and maintainable.

2) Creating My First App:

I created my first Django app using the command:

python manage.py startapp blogs

This generated a new folder with files like models.py, views.py, and admin.py.

3) Registering the App:
To make Django aware of my new app, I added it to the "INSTALLED_APPS" list in settings.py. This step is crucial because it tells Django to include the app in the project’s ecosystem.

Image description

4) Understanding Models: I got introduced to models, which are Python classes that define the structure of your database tables. For example, I created a simple model for a blog post:

from django.db import models

class Blog(models.Model):
head = models.CharField(max_length=100)
description = models.TextField()
author = models.ForeignKey(User, on_delete= models.CASCADE, related_name="blogs")
published_at = models.DateTimeField(auto_now_add=True)
blog_image = models.ImageField(null=True, blank= True, upload_to="images/")

Models are the backbone of Django’s ORM (Object-Relational Mapping), making database interactions seamless.

Image description

5) *Running Migrations: *
After defining my model, I ran migrations to create the corresponding database table:

python manage.py makemigrations
python manage.py migrate

Seeing Django automatically generate SQL commands for my model was mind-blowing! ✨

Why Does This Matter?
Understanding how to structure your project with apps and models helps keep your work organized and scalable. Plus, Django’s ORM eliminates the need to write raw SQL queries, saving time and reducing errors.

Looking Ahead:
Today helped me see how all the pieces of a Django project fit together. Tomorrow, I’ll explore views and URLs—the parts that manage how users interact with the app. I’m excited to see how data flows through the system! 🔗

If you’re exploring Django too or have tips on structuring apps, I’d love to connect and learn from you. Let’s grow together in this tech journey! 🤝

Stay tuned for more updates as I continue this journey. Day 3 is just around the corner, and I’m excited to see what’s next! 🚀

Happy coding! 😊

Top comments (0)