Overview
The E-commerce API is built around several core models that represent products, orders, customers, and promotional offers. Understanding these models and their relationships is essential for effective API integration.Product Catalog
Product Model
The central model for product information. Location:catalogue/models.py:38
Key Fields
Product name (unique, indexed)
Product category reference
Detailed product description
Store/vendor that owns this product
Base price (10 digits, 2 decimal places)
Shipping cost (6 digits, 2 decimal places)
Average rating calculated from reviews
Whether product has variants. False if product has multiple variants.
Total stock across all variants
Total units sold across all variants
Product availability status
Important Methods
Database Indexes
Category Model
Organizes products into hierarchical categories. Location:catalogue/models.py:20
Category name (max 50 chars, indexed)
URL-friendly identifier (auto-generated from name)
ProductVariant Model
Represents different variations of a product (e.g., size, color). Location:catalogue/models.py:147
Key Fields
Parent product
Stock Keeping Unit (unique, max 20 chars, indexed)
Whether this is the default variant
Amount to add/subtract from base price
Available stock for this variant
Total units sold
Pricing Logic
Standalone products must have exactly one default variant. Products with
is_standalone=False can have multiple variants.ProductAttribute & VariantAttribute
Define customizable attributes for products and their variants. Location:catalogue/models.py:127-210
ProductAttribute
Defines available attributes for a product (e.g., “Size”, “Color”).VariantAttribute
Assigns specific values to variant attributes (e.g., “Size: Large”).ProductMedia Model
Handles images and videos for products with validation. Location:catalogue/models.py:212
Associated product
Image or video file (validated)
Whether this is the primary media
Supported Formats
Images:- JPEG (.jpg)
- PNG (.png)
- WebP (.webp)
- MP4 (.mp4)
- WebM (.webm)
Review Model
Customer reviews and ratings for products. Location:catalogue/models.py:286
Customer who wrote the review
Product being reviewed
Review content
Rating (1-5): 1=Very Bad, 2=Unsatisfied, 3=Just There, 4=Satisfied, 5=Very Satisfied
Sentiment analysis result: POSITIVE, Neutral, or Negative
Numerical sentiment score
Reviews automatically update the product’s average rating on save.
Orders
Order Model
Represents a customer’s order. Location:orders/models.py:16
Key Fields
Unique order identifier (auto-generated)
Customer who placed the order
Billing address reference
Order status:
paid, awaiting_payment, delivered, or cancelledApplied order-level offer
Applied voucher code (one per order)
Total discount from voucher
Final order total (calculated on save)
Order Calculations
Database Indexes
OrderItem Model
Individual items within an order. Location:orders/models.py:150
Parent order
Product variant purchased
Product reference
Price per unit (editable=False)
Number of units
Shipping fee for this item
Product-level offer applied
Discount from product offer
Total price for this line item (editable=False)
Creating from Cart
Customers
Customer Model
Custom user model using email authentication. Location:customers/models.py:32
Email address (unique, indexed, used for login)
Customer’s first name
Customer’s last name
URL-friendly identifier (auto-generated from full name)
Customer’s birth date
Primary address
Whether customer is also a vendor
Date of most recent purchase
Total number of unique products purchased
Total units purchased across all orders
Product variants the customer has purchased
Vouchers the customer has used
Customer Properties
Address Model
Shipping and billing addresses. Location:customers/models.py:14
Street address (max 30 chars)
Postal/ZIP code
City name (max 50 chars)
State/province (max 50 chars)
Country name (max 30 chars)
Discounts & Promotions
Offer Model
Promotional offers applicable to products or orders. Location:discount/models.py:23
Key Fields
Offer title (max 50 chars)
Store offering the promotion
Type:
product (product-level) or order (order-level)Type:
percentage or fixedDiscount amount (percentage or fixed value)
Whether a voucher code is required
Total discount given (tracks usage)
Maximum total discount this offer can provide
Offer start date/time
Offer end date/time
Customers who have claimed this offer
Offer Methods
Database Indexes
OfferCondition Model
Defines eligibility criteria for offers. Location:discount/models.py:317
Type:
specific_products, specific_categories, customer_groups, or min_order_valueAssociated offer
Minimum order value (for min_order_value type)
Customer group:
first_time_buyers or all_customersSpecific products (for specific_products type)
Specific categories (for specific_categories type)
Each offer can have multiple conditions. All conditions must be satisfied for the offer to apply.
Voucher Model
Discount codes that customers can apply at checkout. Location:discount/models.py:413
Voucher name
Voucher description
Voucher code (unique, indexed, auto-uppercased)
Associated offer
Type:
single (one time), multiple (reusable), or once_per_customerMaximum number of times voucher can be used
Current usage count
Voucher validity start
Voucher validity end
Voucher Validation
Database Indexes
Model Relationships
Product Catalog Relationships
Order Relationships
Discount Relationships
Next Steps
Architecture
Learn about the overall architecture and design patterns
Filtering & Pagination
Learn how to filter, search, and paginate API results