Get cart total не вызывается... логика get_product работала раньше и все еще работает, но теперь почему она показывает ошибку?
models.py\account
class Cart(models.Model):
user = models.ForeignKey(User, on_delete=models.CASCADE)
is_paid = models.BooleanField(default=False)
def __str__(self):
return str(self.user)
def get_cart_total(self):
cart_item = self.cart_item.all()
price = []
for cart_item in cart_items:
price.append(cart_item.product.discounted_price)
if cart_item.color_variant:
color_variant_price = cart_item.color_variant.price
price.append(color_variant_price)
if cart_item.size_variant:
size_variant_price = cart_item.size_variant.price
price.append(size_variant_price)
print(price)
return sum(price)
class CartItem(models.Model):
cart = models.ForeignKey(Cart, on_delete=models.CASCADE)
product = models.ForeignKey(Product, on_delete=models.CASCADE)
color_variant = models.ForeignKey(ColorVariant, on_delete=models.SET_NULL, null=True, blank=True)
size_variant = models.ForeignKey(SizeVariant, on_delete=models.SET_NULL, null=True, blank=True)
quantity = models.PositiveIntegerField(default=0)
coupon = models.ForeignKey(Coupon, on_delete=models.SET_NULL, null=True, blank=True)
def get_product_price(self):
price = [self.product.discounted_price]
if self.color_variant:
color_variant_price = self.color_variant.price
price.append(color_variant_price)
if self.size_variant:
size_variant_price = self.size_variant.price
price.append(size_variant_price)
return sum(price)
views.py/shop
def get_product(request,slug):
try:
product = Product.objects.get(slug=slug)
context = {'product':product}
if request.GET.get('size'):
size = request.GET.get('size')
price = product.get_product_price_by_size(size)
context['selected_size'] = size
context['updated_price'] = price
print(price)
return render(request, 'app/product-single.html',context = context )
except Exception as e:
print(e)
Продукт, соответствующий запросу, не существует.
Внутренняя ошибка сервера: /favicon.ico/
Traceback (last recent call last):
File "D:\online shopping\env\lib\site-packages\django\core\handlers\exception.py", line 55, in inner response = get_response(request)
File "D:\online shopping\env\lib\site-packages\django\core\handlers\base.py", line 204, in _get_response
self.check_response(response, callback)
File "D:\online shopping\env\lib\site-packages\django\core\handlers\base.py", line 332, in check_response
raise ValueError(
ValueError: Представление shop.views.get_product не вернуло объект HttpResponse. Вместо этого оно вернуло None.
[19/Aug/2022 11:45:30] "GET /favicon.ico/ HTTP/1.1" 500 63121
[19/Aug/2022 11:45:33] "GET /account/cart/ HTTP/1.1" 200 8204
Не найдено: /account/cart/media/bg_6.jpg
>[19/Aug/2022 11:45:33] "GET /account/cart/media/bg_6.jpg HTTP/1.1" 404 5829
[19/Aug/2022 11:49:00] "GET /account/cart/ HTTP/1.1" 200 8204
Не найдено: /account/cart/media/bg_6.jpg
>[19/Aug/2022 11:49:01] "GET /account/cart/media/bg_6.jpg HTTP/1.1" 404 5829
D:\online shopping\nykaa\account\models.py изменен, перезагрузка.
Слежение за изменениями файлов с помощью StatReloader
Выполнение проверки системы...