Creating the order model
To store the purchase information, we need to start by creating an Order Django model. The following are the three steps for storing the purchase information:
- Create the Order model.
- Apply migrations.
- Add the order model to the admin panel.
Let’s go through them in detail.
Creating the Order model
We will start creating the Order model. We will create this model inside the cart app.
In /cart/models.py
file, add the following in bold:
from django.db import models from django.contrib.auth.models import User class Order(models.Model): id = models.AutoField(primary_key=True) total = models.IntegerField() date = models.DateTimeField(auto_now_add=True) user = models.ForeignKey(User, on_delete=models.CASCADE) def __str__(self): ...