ecommerce-2-api
ecommerce-2-api copied to clipboard
Confusion between Cart and CartItem
I got confuse with the model carts because there are two tables used Cart and CartItem. Can you tell me their purposes with an example, please? Because if the model was something like this then i understand
class Cart(models.Model):
user = models.ForeignKey(settings.AUTH_USER_MODEL, null=True, blank=True, on_delete=models.CASCADE)
timestamp = models.DateTimeField(auto_now_add=True, auto_now=False)
updated = models.DateTimeField(auto_now_add=False, auto_now=True)
class CartItem(models.Model):
cart = models.ForeignKey(Cart, on_delete=models.CASCADE)
product = models.ForeignKey(Product, on_delete=models.CASCADE)
quantity = models.PositiveIntegerField(default=1)
# line_item_total also i could not understand.
line_item_total = models.DecimalField(max_digits=10, decimal_places=2)
But you have used items twice both in Cart and Cart Items. In cart as M2M field and in CartItem as FK.
Sorry i could not understand. Can you please explain this?