Install

Ensure that python is already installed.

install virtual environment

pip install virtualenvwrapper-win

Create virtual environment

mkvirtualenv djangoprj

Install Django

ensure that you are inside the virtual environment

pip install django

Run below command to check django is installed

django-admin --version

Create project

django-admin startproject djsample

Run project

cd djsample

py manage.py runserver

Do not close the above window.

open http://localhost:8000 in browser.

stop the running server and move to next step.

Enter to virtual environment

from command prompt to enter into virtual environment

workon djangoprj

Admin panel

create simple app

python manage.py startapp app

a new folder app has been created

Database

Install posgreSQL library

pip install psycopg2

update below database config at settings.py

DATABASES = {
    'default': {
        'ENGINE': 'django.db.backends.postgresql',
        'NAME': 'mydatabase',
        'USER': 'mydatabaseuser',
        'PASSWORD': 'mypassword',
        'HOST': '127.0.0.1',
        'PORT': '5432',
    }
}

Create model from existing database

Run below command to auto generate models. This will overwrite the exisitng models.py file.

python manage.py inspectdb > .\app\models.py

migration

python manage.py migrate

by running the above command, few tables are created automatically.

Create super user

python manage.py createsuperuser

Run and check

Start the server

py manage.py runserver

Go to http://localhost:8000/admin

stop the running server and move to next step.

Config

add app.apps.AppConfig inside INSTALLED_APPS section in settings.py file

Type below code admin.py file

from django.contrib import admin
from .models import Company, Medicine

# Register your models here.
admin.site.register(Company)
admin.site.register(Medicine)