Django step by step ( Part - 1 )
Table of contents
No headings in the article.
Beat way to learn something is to start building some project
# Multi-vendor-ecommerce Application ๐
This is the Multi-Vendor ecommerce website. Customers can purcahse
web scripts for various technologies. like Theme forest, inverto etc.
## Project Setup
create a folder (django-backend) and (react-frontend) for your project first before
running these commands.
-multi-vendor-ecommerce
--| django-backend
--| react-frontend
### Django Backend setup
* cd django-backend
#### Installation
Install pipenv with pip
* pip install pipenv
#### To start the existing project
* pipenv shell
* python manage.py runserver
#### To create a existing project
* pipenv shell
* pip install django
* django-admin startproject core .
* python manage.py runserver
### Install PostgreSQL and PgAdmin4
* PgAdmin is the GUI Interface for the PostgreSQL Database likewise we use MySQL Workbanch for MySQL Database
pgadmin.org/download/pgadmin-4-macos
#### Install Packages to connect PostgreSQL with Django
* pip install psycopg2-binary
### Configure Database in the Settings.py file
``` DATABASES = { 'default': { 'ENGINE': 'django.db.backends.postgresql', 'NAME': 'multivendor_database', 'USER': 'postgres', 'PASSWORD': 'your_password', 'HOST': 'localhost', } } ```
### Befor migrations we should extend user class
* First we will create user module
* Run command: django-admin startapp users
###### Whenever we install any app we need to include that in setting.py file
``` INSTALLED_APPS = [ 'users', 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', ] ```
and Include User model
``` AUTH_USER_MODEL = 'users.user' ```
and Change the Time Zone as well
``` TIME_ZONE = 'Asia/Kolkata' ```
* whenever user loads users -> apps.py loads automatically
__In users --> apps.py__
``` from django.apps import AppConfig class UsersConfig(AppConfig): default_auto_field = 'django.db.models.BigAutoField' name = 'users' ```
__In users --> model.py__
extend User class
``` from django.db import models from django.contrib.auth.models import AbstractUser # Create your models here. class User(AbstractUser): pass ```
We can extend AbstractUser or AbstractBaseUser class according to our need
AbstractUser - Django fields + custom fields
AbstractBaseUser - Custom fields
__In users --> admin.py__
Register user model in admin site so that you can see user table in django admin
``` from django.contrib import admin from .models import User # Register your models here. admin.site.register(User) ```
#### Now we need to make migrations for users model and migrate
* python manage.py makemigrations users
* python manage.py migrate
#### After Migrations we need to create Super User for our Application
* python manage.py createsuperuser
#### We can access our Admin Panel with this URL
## Install Django Rest Framework
Follow the guide -
* pip install djangorestframework
``` INSTALLED_APPS = [ ... 'rest_framework', ] ```
## Now let's start with Database models
Before creating the Database models we need to know the Database Architecture
### First let's think what will be the features of the applications -
Features :
Website-
* Home Page
* Header
* Latest Projects
- Popular Categories (According to product downloads count)
- Popular Projects (According to product downloads count)
- Popular Sellers (According to product downloads count)
* Customer Rating & Reviews
* Footer
* All Category List
* All product list according to category
* Sort according to price, latest, alphabet, views
* Product Detail
* Checkout Page
* Order Success Page
* Order Failure Page
* Multilingua
### For this we will create ER-Diagram and Schema Diagrams -
__ER Diagram__ -
## Django Commands
### After installation of any packages
* pip freeze > requirements.txt