Better Programming

Advice for programmers.

Follow publication

Member-only story

Everything You Need to Know About Django Models in Python

Esther Vaati
Better Programming
Published in
8 min readNov 9, 2021

Photo by Darren Bockman on Unsplash

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.

movie_library

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;

Create an account to read the full story.

The author made this story available to Medium members only.
If you’re new to Medium, create a new account to read this story on us.

Or, continue in mobile web

Already have an account? Sign in

Esther Vaati
Esther Vaati

Written by Esther Vaati

Get practical JavaScript tips and code snippets delivered to your inbox. Join 1000 + developers who write better code. https://practicaljavascript.substack.com/

Responses (3)

Write a response

I loved this tutorial :) Thank you.

--

MTV is (or used to be) a music channel. The framework is usually referred to as MVT.

--

Check the choices, they are wrong. And I recommend using enumeration types, they are more concise.

--