A
A
Alexander2019-05-30 19:09:49
Django
Alexander, 2019-05-30 19:09:49

How to save size to cart in django-oscar?

Hello, I'm trying to customize saving a product to the cart.
First I changed the model

from oscar.apps.basket.abstract_models import AbstractLine

class Line(AbstractLine):
    size = models.IntegerField(default=0)

After changing shape
<form id="add_to_basket_form" action="{% url 'basket:add' pk=product.pk  %}" method="post" class="add-to-basket">
        {% csrf_token %}
        {% include "partials/form_fields.html" with form=basket_form %}
        {{basket_form.size}}
        <button type="submit" class="btn btn-lg btn-primary btn-add-to-basket" value="{% trans "Add to basket" %}" data-loading-text="{% trans 'Adding...' %}">{% trans "Add to basket" %}</button>
</form>

I'm trying to add the size field as above in the html code, but I can't find it.
Tried to change shape
from oscar.apps.basket.forms import AddToBasketForm, 
class AddToBasketForm(AddToBasketForm):
    def __init__(self, *args, **kwargs):
        return super().__init__(*args, **kwargs)

    size = forms.CharField()
    
    class Meta:
        fields = '__all__'

Can't find it either, can you tell me what to do next? It turns out that I want to display the size field in the form and save it to the basket of the product.

Answer the question

In order to leave comments, you need to log in

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question