Товар Django не добавляется в корзину

Я пытаюсь добавить корзину на свой сайт с помощью Django. У меня есть некоторые проблемы: Я не могу добавить товар в корзину и по какой-то причине у меня нет выбора количества этого товара

это моя страница

это то, что мне нужно

это моя корзина

urls.py

path('cart/', cart_detail, name='cart_detail'),
path('cart/add/<int:post_id>/', cart_add, name='cart_add'),
path('cart/remove/<int:post_id>/', cart_remove, name='cart_remove'),

views.py

@require_POST
def cart_add(request, post_id):
    cart = Cart(request)
    post = get_object_or_404(Posts, id=post_id)
    form = CartAddProductForm(request.POST)
    if form.is_valid():
        cd = form.cleaned_data
        cart.add(post=post,
                 quantity=cd['quantity'],
                 update_quantity=cd['update'])
    return redirect('cart_detail')


def cart_remove(request, post_id):
    cart = Cart(request)
    post = get_object_or_404(Posts, id=post_id)
    cart.remove(post)
    return redirect('cart_detail')


def cart_detail(request):
    cart = Cart(request)
    return render(request, 'store/detail.html', {'cart': cart})


def product_detail(request, post_id, slug):
    product = get_object_or_404(Posts,
                                id=post_id,
                                slug=slug,
                                available=True)
    cart_product_form = CartAddProductForm()
    return render(request, 'store/detail.html', {'product': product,
                                                        'cart_product_form': cart_product_form})

моя форма в html-файле

<form action="{% url  'cart_add' post.id %}" method="post">
    {{ cart_product_form }}
    {% csrf_token %}
    <input type="submit" value="Add to cart">
</form>

cart.py

from decimal import Decimal
from django.conf import settings
from .models import Posts


class Cart(object):

    def __init__(self, request):
        self.session = request.session
        cart = self.session.get(settings.CART_SESSION_ID)
        if not cart:
            cart = self.session[settings.CART_SESSION_ID] = {}
        self.cart = cart


    def add(self, post, quantity=1, update_quantity=False):
        post_id = str(post.id)
        if post_id not in self.cart:
            self.cart[post_id] = {'quantity': 0,
                                     'price': str(post.price)}
        if update_quantity:
            self.cart[post_id]['quantity'] = quantity
        else:
            self.cart[post_id]['quantity'] += quantity
        self.save()


    def save(self):
        self.session[settings.CART_SESSION_ID] = self.cart
        self.session.modified = True

    def remove(self, post):
        post_id = str(post.id)
        if post_id in self.cart:
            del self.cart[post_id]
            self.save()


    def __iter__(self):
        post_ids = self.cart.keys()
        posts = Posts.objects.filter(id__in=post_ids)
        for post in posts:
            self.cart[str(post.id)]['post'] = post

        for item in self.cart.values():
            item['price'] = Decimal(item['price'])
            item['total_price'] = item['price'] * item['quantity']
            yield item


    def __len__(self):
        return sum(item['quantity'] for item in self.cart.values())


    def get_total_price(self):

        return sum(Decimal(item['price']) * item['quantity'] for item in
                   self.cart.values())


    def clear(self):
        del self.session[settings.CART_SESSION_ID]
        self.session.modified = True

forms.py

class CartAddProductForm(forms.Form):
    quantity = forms.TypedChoiceField(choices=POST_QUANTITY_CHOICES, coerce=int)
    update = forms.BooleanField(required=False, initial=False, widget=forms.HiddenInput)

У меня есть только кнопка "добавить в корзину", которая не работает без выбора количества

Вернуться на верх