Hola me sale el siguiente error, como hago? DoesNotExist at /carrito/ Cart matching query does not exist.
Codigo de models.py from django.db import models from users.models import User from products.models import Product from django.db.models.signals import pre_save
Create your models here.class Cart(models.Model): cart_id = models.CharField(max_lenght=100, null=False, blank=False, unique=True) user = models.ForeignKey(User, null=True, blank=True, on_delete=models.CASCADE) products = models.ManyToManyField(Product) subtotal = models.DecimalField(default=0.0, max_digits=8, decimal_places=2) total = models.DecimalField(default=0.0, max_digits=8, decimal_places=2) created_at = models.DateTimeField(auto_now_add=True) def str(self): return ''
Codigo de views.py from django.shortcuts import render from .models import Cart
Create your views here.def cart(request): user = request.user if request.user.is_authenticated else None if request.session.get('cart_id'): cart = Cart.objects.get(pk=request.session.get('cart_id')) else: cart = Cart.objects.create(user=user) request.session['cart_id'] = cart.id return render(request, 'carts/cart.html', { })