Answer the question
In order to leave comments, you need to log in
How to get a discount in a function?
There is a discount method in the product model
def get_sale(self):
'''Расчитать стоимость со скидкой'''
price = int(self.price * (100 - self.discount) / 100)
return price
# Страница товара
def ProductDetail(request, id, slug):
top_five_products = Product.objects.all().exclude(id=id).order_by()[:10]
alboms = Albom.objects.filter(product=id)
product = get_object_or_404(Product, id=id, slug=slug, available=True)
cart_product_form = CartAddProductForm()
return render(request, 'shop/product/detail.html', {'product': product,
'cart_product_form': cart_product_form,
'alboms': alboms,
'top_five_products': top_five_products})
<form action="{% url "cart:CartAdd" product.id %}" method="post" class="add">
{% csrf_token %}
<p>{{ cart_product_form }}</p>
</div>
<div class="single-item-more-action">
<input type="image" src="{% static 'img/item-action-btn.png' %}">
</div>
</form>
Answer the question
In order to leave comments, you need to log in
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question