Registering customer orders
When a shopping cart is checked out, you need to save an order in the database. Orders will contain information about customers and the products they are buying.
Create a new application for managing customer orders using the following command:
python manage.py startapp orders
Edit the settings.py
file of your project and add the new application to the INSTALLED_APPS
setting, as follows:
INSTALLED_APPS = [
# ...
'shop.apps.ShopConfig',
'cart.apps.CartConfig',
'orders.apps.OrdersConfig',
]
You have activated the orders
application.
Creating order models
You will need a model to store the order details and a second model to store items bought, including their price and quantity. Edit the models.py
file of the orders
application and add the following code to it:
from django.db import models
from shop.models import Product
class Order(models.Model):
first_name = models.CharField...