Using Models
A model is a class that represents a database table. It defines the structure, fields, and behavior of the data stored in the table. By default, Django uses SQLite as its database engine, which is a lightweight, file-based database that doesn’t require additional setup. However, if you can use other database engines such as MySQL.
In this example we’re going to use a model to create a blog post application for our website. Navigate to the directory where the project was created. For example, my project is in the directory myweb
cd pyweb
Create a new app called blog. Run the following command
python manage.py startapp blog
Next, we need to define our model. In the app directory (blog), open the models.py file
from django.db import ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access