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 modelsfrom shop.models import Productclass Order(models.Model):    first_name = models.CharField(max_length=50)    last_name = models.CharField(max_length=50)    email = models.EmailField()    address = models.CharField(max_length=250)    postal_code = models.CharField(max_length=20)    city = models.CharField(max_length=100)    created = models.DateTimeField(auto_now_add=True)    updated = models.DateTimeField(auto_now=True)    paid = models.BooleanField(default=False)    class Meta:        ordering = ('-created',) def __str__(self): ...

Get Django 2 by Example now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.