E-commerce Platform
Build a complete e-commerce platform with Django including product management, shopping cart, payment processing, and order management. This project combines models, views, templates, and third-party integrations into a production-ready online store.
90 min•By Priygop Team•Last updated: Feb 2026
E-commerce Architecture
A Django e-commerce platform typically uses multiple apps: products (catalog), cart (session-based or DB-backed), orders (checkout & fulfillment), accounts (user profiles), and payments (gateway integration). Each app follows Django's MTV pattern with models defining the schema, views handling business logic, and templates rendering the storefront.
Key Features
- Product catalog with categories, search, and filtering using Django ORM lookups
- Session-based shopping cart with add, update, and remove functionality
- Stripe/Razorpay payment gateway integration with webhooks
- Order management with status tracking (pending, paid, shipped, delivered)
- User authentication with django-allauth for social login support
- Admin dashboard using Django's built-in admin with custom actions
Product Model & Cart Logic
Example
# products/models.py
from django.db import models
from django.urls import reverse
class Category(models.Model):
name = models.CharField(max_length=200)
slug = models.SlugField(unique=True)
class Meta:
verbose_name_plural = "categories"
def __str__(self):
return self.name
class Product(models.Model):
category = models.ForeignKey(Category, on_delete=models.CASCADE, related_name="products")
name = models.CharField(max_length=200)
slug = models.SlugField(unique=True)
description = models.TextField(blank=True)
price = models.DecimalField(max_digits=10, decimal_places=2)
image = models.ImageField(upload_to="products/", blank=True)
stock = models.PositiveIntegerField(default=0)
available = models.BooleanField(default=True)
created = models.DateTimeField(auto_now_add=True)
updated = models.DateTimeField(auto_now=True)
def __str__(self):
return self.name
def get_absolute_url(self):
return reverse("product_detail", args=[self.slug])
# cart/cart.py — Session-based cart
class Cart:
def __init__(self, request):
self.session = request.session
cart = self.session.get("cart")
if not cart:
cart = self.session["cart"] = {}
self.cart = cart
def add(self, product, quantity=1):
product_id = str(product.id)
if product_id not in self.cart:
self.cart[product_id] = {"quantity": 0, "price": str(product.price)}
self.cart[product_id]["quantity"] += quantity
self.save()
def remove(self, product):
product_id = str(product.id)
if product_id in self.cart:
del self.cart[product_id]
self.save()
def save(self):
self.session.modified = True
def get_total_price(self):
from decimal import Decimal
return sum(
Decimal(item["price"]) * item["quantity"]
for item in self.cart.values()
)Try It Yourself — E-commerce Platform
Try It Yourself — E-commerce PlatformHTML
HTML Editor
✓ ValidTab = 2 spaces
HTML|38 lines|1949 chars|✓ Valid syntax
UTF-8