2016-10-06から1日間の記事一覧
jQueryでフラッシュメッセージを表示させる。 product_detail.html に試しに入れてみる。 <div class="alert alert-success alert-dismissible" role="alert"> <button type="button" class="close" data-dismiss="alert" aria-label="Close"><span aria-hidden="true">×</span></button> <strong>Warning!</strong> Better check yourself, you'r…</div>
Cartの中で数量を変更したら、自動的に合計も計算される view.html を編集 タグを、更新などと一緒のテーブルに入れる。 <td> <form action="." method="GET"> <input type='hidden' name='item' value='{{ item.item.id }}'/> <input type='number' class='item-qty' name='qty' value='{{ item.quantity }}'/> </form></td>
Ajax を使う part1 products/product_detail.html のform タグにidをつけていく <form id='add-form' method='GET' action="{% url 'cart' %}"> <input class='form-control' type='number' name='qty' value='1' /> block jQuery にadd cartに関するajaxを書いていく。 <script> {% block jquery %} ... $("#submit-btn").click(function(event){ ev…</form>
cartのsubtotalを表示する。 carts/models.py に追記 subtotal fieldを追加。subtotalのアップデートfunctionを追記する。 class Cart(models.Model): ... subtotal = models.DecimalField(max_digits=50, decimal_places=0, null=True, blank=True) def __s…
pre-save signalを使って、line itemのtotalを表示する CartItemにline_item_totalを追記 class CartItem(models.Model): cart = models.ForeignKey("Cart") item = models.ForeignKey(Variation) quantity = models.PositiveIntegerField(default=1) line_i…