This Django project is aimed at getting you started with Django and moving you into more advanced topics as the project progresses. In this tutorial we go through the process of building a shopping basket using sessions to handle managing data anonymous connections, saving products into a shopping cart in preparation to be purchased. We implement Ajax to handle the front-end and work through stage by stage the functionality needed to save, update and delete the basket data.

0:00​ Introduction
0:33​ Where we finished the last tutorial
1:17​ Preview of what we are going to build
2:54​ Stages of this tutorial

Refactoring Tasks (optional tasks):

06:34​ Refactoring Introduction

Preparing for refactoring

07:10​ Downloading previous tutorial code
08:10​ Open code with Visual studio Code
08:28​ Build virtual environment and install dependencies

Starting to refactor project

10:59​ Reconfigure the context processor
13:42​ Remove redundant links from navbar
15:35​ Visual change to homepage element
16:38​ Creating a new custom object manager
20:42​ Removing comments from settings.py
21:18​ Renaming views
24:26​ SEO - Changing the page titles
25:16​ Changing the template names
26:59​ Changing the URL structures - Store items
28:57​ gitignore file
31:27​ Model - adding a default image
33:46​ Changing the URL structures - Store category
34:17​ Creating a test to check AllOWED_HOSTS
39:09​ Flake8 and isort - PEP 8 compliance
40:33​ Testing - Run and Change test parameters
44:20​ Setup static folder

Important
Ajax will not work with the slim version of jQuery - minified version is okay.


45:50​ Updating the Bootstrap & jQuery CDN links
47:04​ Finished refactoring

Code Repository (After Refactoring):
https://github.com/veryacademy/YT_Dja…​

Introducing Sessions (optional step):

48:10​ Introduction to sessions
51:45​ Visual explanation of sessions
56:32​ Viewing the Django database - session table
01:02:18​ Viewing the session in the browser console
01:04:20​ Django required resources to enable sessions

Development Part 1.0 (Preparing the project):

01:05:30​ Introduction
01:08:24​ Create a new app - basket
01:08:56​ Remove unnecessary files
01:09:20​ Configure the URL’s for the basket
01:13:58​ Building the basket summary view
01:15:50​ Building the basket summary template
01:21:45​ Making the basket icon/button for the navbar
01:28:04​ VSC extension for formatting HTML/Python template files

Development Part 1.2 (Building a Session):

01:30:06​ Building sessions
01:40:44​ Building the context_processor file
01:44:48​ Testing the initial session setup

Development Part 1.3 (Creating add functionality):

01:49:25​ Building the add to cart button functionality (Ajax)
02:03:45​ URL for a the add function
02:04:05​ view for the add function
02:08:31​ updating the basket class
02:20:52​ Adding the Qty to the session data

Development Part 2.0 (Deleting basket/session data):

02:40:29​ Introduction - deleting session data
02:41:41​ Creating the basket summary template
02:46:21​ Iterating over the session data
03:03:08​ Get the total price of the basket items

Development Part 2.1(Front-end - deleting basket/session data):

03:07:21​ Introduction - Ajax for deleting items
03:08:35​ Creating Ajax for deleting basket items
03:12:00​ Building a basket URL
03:13:09​ Creating a delete function in view
03:14:47​ Handling remove items in the basket class
03:22:09​ Resolving the unique DOM ID issue with Ajax
03:24:27​ Removing elements from the page with JavaScript

Development Part 3.0 (Updating basket/session data):

03:29:01​ Introduction - updating session data
03:29:49​ Capturing the user selection
03:34:36​ Create a URL for updating data
03:34:51​ Create the view function
03:36:49​ Further developing the basket class
03:43:14​ Developing the front-end code for update
03:48:35​ Resolving known issues
03:55:52​ Resolving final issue

Testing

04:00:05​ Introduction
04:01:11​ Running existing tests
04:05:18​ Running coverage - assessing tests required
04:07:15​ Building tests for the basket app

Starting code(with refactoring completed):

Final Code:

Subscribe: https://www.youtube.com/channel/UC1mxuk7tuQT2D0qTMgKji3w

#python #django

Build an Ecommerce Basket with Session Handling Using Python Django
13.30 GEEK