<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>
# Добавление товара в корзину пользователя или обновление количества товара
def add(self, product, quantity=1, update_quantity=False):
product_id = str(product.id)
if product_id not in self.cart:
self.cart[product_id] = {'quantity': 0,
'price': str(product.price)}
if update_quantity:
self.cart[product_id]['quantity'] = quantity
else:
self.cart[product_id]['quantity'] += quantity
self.save()
@property
def get_final_price(self):
return self.price - self.price * self.discount
# Добавление товара в корзину пользователя или обновление количества товара
def add(self, product, quantity=1, update_quantity=False):
product_id = str(product.id)
if product_id not in self.cart:
self.cart[product_id] = {'quantity': 0,
'price': str(product.price)}
if update_quantity:
self.cart[product_id]['quantity'] = quantity
else:
self.cart[product_id]['quantity'] += quantity
self.save()
<div class="hd-block">
<nav id="main-nav">
<ul id="main-menu">
<li><a href="video.html">Видео</a></li>
<li {% if not category %} class="has-children" {% endif %}><a href="{% url "shop:ProductList" %}">Каталог</a>
<ul class="sub-menu">
{% for cat in categories %}
<li {% if category.slug == cat.slug %} class="selected" {% endif %}>
<a href="{{ cat.get_absolute_url }}">{{ cat.name }}</a>
</li>
{% endfor %}
</ul>
</li>
<li><a href="oplata_dostavka.html">Оплата и доставка</a></li>
<li><a href="otzivi.html">Отзывы</a></li>
<li><a href="faq.html">Вопрос-Ответ</a></li>
</ul>
</nav>
</div>
<div class="hd-block">
<nav id="main-nav">
<ul id="main-menu">
<li><a href="video.html">Видео</a></li>
<li {% if not category %} class="has-children" {% endif %}><a href="{% url "shop:ProductList" %}">Каталог</a>
<ul class="sub-menu">
{% for cat in categories %}
<li {% if category.slug == cat.slug %} class="selected" {% endif %}>
<a href="{{ cat.get_absolute_url }}">{{ cat.name }}</a>
</li>
{% endfor %}
</ul>
</li>
<li><a href="oplata_dostavka.html">Оплата и доставка</a></li>
<li><a href="otzivi.html">Отзывы</a></li>
<li><a href="faq.html">Вопрос-Ответ</a></li>
</ul>
</nav>
</div>
def ExportToCSV(modeladmin, request, queryset):
opts = modeladmin.model._meta
response = HttpResponse(content_type='text/csv')
response['Content-Disposition'] = 'attachment; \
filename=Orders-{}.csv'.format(datetime.datetime.now().strftime("%d/%m/%Y"))
response.write(codecs.BOM_UTF8)
writer = csv.writer(response, delimiter=str(';'), quoting=csv.QUOTE_ALL)
fields = [field for field in opts.get_fields() if not field.many_to_many and not field.one_to_many]
# Первая строка- оглавления
writer.writerow([field.verbose_name.encode("utf8") for field in fields])
# Заполняем информацией
for obj in queryset:
data_row = []
for field in fields:
value = getattr(obj, field.name)
if isinstance(value, six.string_types):
data_row.append(value.encode('utf8'))
writer.writerow(data_row)
else:
data_row.append(value)
return response
ExportToCSV.short_description = 'Export CSV'