Member-only story
Everything You Need to Know About Django Models in Python
A comprehensive guide to Django Models
Django is a high-level web framework written in python. It is used to build complex database-driven applications. Django uses the MVT framework. The MVT framework consists of the following components:
- Model
- View
- Template
In this tutorial, we will cover everything needed to know about models in Django, and by the end of the tutorial, you will be in a position to
- Create a Django project
- Represent objects in Django using models.
Setup a Django Project
We will start by creating a new Django project. Our project will be a Movie database system.
Create a directory and cd into it.
$ mkdir movie_db$ cd movie_db
Create Virtual environment:
$ python3.8 -m venv env
Activate virtual environment:
$ source env/bin/activate
Install Django in the virtual environment:
(env)$ pip install Django
Create a new Django project with the name django_movie
(env)$ django-admin startproject django_movie .
Create a Django app:
(myenv)$ django-admin startapp movie_library
The above command will create the following files.

Add the app to the list of INSTALLED_APPS
in settings.py
.
Models
Models represent objects in a django application. For our application, we need to ask ourselves;