Create a Django project, define your first models, run migrations, and query the database — no raw SQL required.
Django's tooling creates a ready-to-run project structure in seconds.
pip install django
django-admin startproject mysite .
python manage.py startapp blog
# Add 'blog' to INSTALLED_APPS in settings.py
python manage.py runserverfrom django.db import models
from django.contrib.auth.models import User
class Post(models.Model):
title = models.CharField(max_length=200)
slug = models.SlugField(unique=True)
body = models.TextField()
author = models.ForeignKey(User, on_delete=models.CASCADE)
created_at = models.DateTimeField(auto_now_add=True)
published = models.BooleanField(default=False)
class Meta:
ordering = ['-created_at']
def __str__(self):
return self.titlepython manage.py makemigrations
python manage.py migrate
python manage.py createsuperuserpython manage.py shell
>>> from blog.models import Post
>>> Post.objects.all()
>>> Post.objects.filter(published=True)
>>> Post.objects.filter(title__icontains='django')
>>> Post.objects.exclude(published=False)
>>> Post.objects.order_by('-created_at')[:5]
>>> post = Post.objects.get(slug='my-first-post')
>>> post.title
>>> Post.objects.count()blog/admin.py: from .models import Post; admin.site.register(Post). Then visit /admin with your superuser credentials. You get a full CRUD UI for free.django-admin startproject and startapp scaffold your project structure.makemigrations generates migration files. migrate applies them to the database..filter(), .exclude(), .get(), .order_by(), .count().