..\\tutorial> python -m venv venv
Code above said that we created .env virtual environment inside the tutorial folder. Then, activate the virtual environment using :
..\\tutorial> cd venv
..\\tutorial\\venv> Scripts\\activate
If you run code above successfully, you will find the following command on the terminal, and the virtual environment is ready to go
(venv) ..\\tutorial\\venv>
2. If you are using VSCode, make sure you change the interpreter on current virtual environment with command palette or by press Ctrl + Shift + F. You can find the command palette at View tab.

Choose the virtual environment at current folder as interpreter, on this article, the `venv` virtual environment

(venv) ..\\tutorial> pip install django (venv) ..\\tutorial> pip install djangorestframework
4. Set up a new django project by using
(venv) ..\\tutorial> django-admin startproject tutorial .
Create the application by typing
(venv) ..\\tutorial> python manage.py startapp api
5. Here is the following folder structure for getting started our django restframework
Before we code our django restframework, we need to register the django restframework and the application. To register, head into settings.py file inside django folder (on this article, django_restframework refers to django folder), scroll down until you find INSTALLED_APPS list, register the django REST framework and the application.
The 'library.apps.LibraryConfig' value basically refers to api folder → apps.py file → ApiConfig class.
We are done with initial project setup, now we are heading for define the model/database
In Django, we define the database with ORM or Object Relational Mapper. In short, ORM wraps how we define table and fetch the record. Here, we define model/table at models.py file which located at api folder. In code below, we define DailyCases model using python class.
from django.db import models
# Create your models here.
class DailyCases(models.Model):
date = models.DateField(blank=False, null=False, unique=True)
cummulative = models.IntegerField(default=0)
recoverd = models.IntegerField(default=0)
under_treatment = models.IntegerField(default=0)
deaths = models.IntegerField(default=0)
def __str__(self):
return str(self.date)
After we define the model, we should register it on admin.py file. The file is located within api folder. To register the model, we use code below.
from django.contrib import admin
from .models import DailyCases
# Register your models here.
admin.site.register(DailyCases)
Next, we should make migrations and migrate to commit changes on our database. We type the following command on terminal/console.
(venv) ..\\tutorial> python manage.py migrate
(venv) ..\\tutorial> python manage.py makemigrations