May 2018
Beginner to intermediate
526 pages
11h 57m
English
Let's start by creating the Coupon model. Edit the models.py file of the coupons application and add the following code to it:
from django.db import modelsfrom django.core.validators import MinValueValidator, \ MaxValueValidatorclass Coupon(models.Model): code = models.CharField(max_length=50, unique=True) valid_from = models.DateTimeField() valid_to = models.DateTimeField() discount = models.IntegerField( validators=[MinValueValidator(0), MaxValueValidator(100)]) active = models.BooleanField() def __str__(self): return self.code
This is the model that we are going to use to store coupons. The Coupon model contains the following fields:
Read now
Unlock full access