Before doing this tutorial, make sure you finish part one and part two.
Now we will create a app name “blog”. Run this in your terminal inside root folder.
python manage.py startapp blog
Our current folders and files.

Object-Relational Mapping (ORM)
Object-Relational Mapping (ORM) is a programming technique that helps connect relational databases with object-oriented programming languages. It serves as a bridge between your code and the database, enabling you to interact with data using objects instead of writing raw SQL queries. Django using ORM interacts with its database models to add, delete, modify, and query objects. Now we will create the database models for our blog app.
Open file “myblog/blog/models.py”
from django.db import models
class Category(models.Model):
name = models.CharField(max_length=50)
class Meta:
verbose_name_plural = "categories"
def __str__(self):
return self.name
class Post(models.Model):
title = models.CharField(max_length=255)
body = models.TextField()
created_on = models.DateTimeField(auto_now_add=True)
last_modified_on = models.DateTimeField(auto_now=True)
categories = models.ManyToManyField("Category", related_name="posts")
def __str__(self):
return self.title
Before we migrate our pending blog database, open file “myblog/blogproject/settings.py” and write this code below into INSTALLED_APPS array. The word “blog” is a folder inside myblog, and “apps” is a python file inside blog folder. The word “BlogConfig” is a class name in apps.py.
'blog.apps.BlogConfig'

Now let’s migrate and synchronize database by running this two instructions in terminal.
python manage.py makemigrations blog
python manage.py migrate blog

We want Post and Category to be displayed on admin dashboard so we can add, update and delete it.
Open file “myblog/blog/admin.py”
from django.contrib import admin
from blog.models import Category,Post
class CategoryAdmin(admin.ModelAdmin):
pass
class PostAdmin(admin.ModelAdmin):
pass
class CommentAdmin(admin.ModelAdmin):
pass
admin.site.register(Category,CategoryAdmin)
admin.site.register(Post,PostAdmin)
This is what adding in our admin dashboard point of view.

Now, adding several categories and posts so we can save in datatbase. You can add random data you like.



Next in part four we will create front end for our website and blog posts. Part four.