text: from django.db import models
  from django.urls import reverse
  from product.models import Product
  
  
  class Customer(models.Model):
      name = models.CharField(max_length=128)
      address = models.TextField()
      postcode = models.CharField(max_length=7)
      phone = models.CharField(max_length=64, blank=True)
      email = models.CharField(max_length=128, blank=True)
      website = models.CharField(max_length=256, blank=True)
  
      class Meta:
          ordering = ["name"]
  
      def __str__(self):
          return self.name
  
      def get_absolute_url(self):
          return reverse("customer_detail", args=[str(self.id)])
  
  
  class CustomerProduct(models.Model):
      customer = models.ForeignKey(
          Customer, on_delete=models.CASCADE, related_name="customer_sold_products"
      )
      product = models.ForeignKey(
          Product, on_delete=models.CASCADE, related_name="product_sold_product"
      )
      name = models.CharField(max_length=128)
      price = models.DecimalField(max_digits=10, decimal_places=2)
  
      class Meta:
          ordering = ["name"]
  
      def __str__(self):
          return self.name
  
      def sold(self):
          try:
              orders = sum(
                  [
                      order.quantity
                      for order in self.product_sales_orders.filter(complete=False)
                  ]
              )
              return orders
          except:
              pass
  