Sobes.tech
Junior — Middle+

Record of individual item purchase

livecode

Task condition

It is necessary to extend the existing models Customer and Item:

  • Create an intermediate model that records the fact of a specific user purchasing a specific product;
  • Add a field to the purchase model indicating the number of units purchased (for example, 2 units of the same product).
class Customer(db.Models):
    full_name = models.CharField(
        max_length=256,
        blank=True,
        default="",
        verbose_name="Name"
    )

class Item(db.Models):
    title = models.CharField(
        max_length=256,
        blank=True,
        default="",
        verbose_name="Title"
    )
    cost = models.DecimalField()

class Purchase(db.Models):
    buyer = models.ForeignKey(Customer, on_delete=models.CASCADE)
    product = models.ForeignKey(Item, on_delete=models.CASCADE)
    quantity = models.PositiveIntegerField(default=1)