django-oscar-change dropdown变种为radioselect

时间:2017-02-19 15:43:43

标签: django django-oscar

我想将下拉变量更改为radioselect。我将篮子应用程序分叉到我的项目中。然后覆盖_create_parent_product_fields。但没有工作

class AddToBasketForm(CoreAddToBasketForm):
    # quantity = forms.IntegerField(initial=1, min_value=1, label=_('Quantity'))

    def __init__(self, basket, product, *args, **kwargs):
        # Note, the product passed in here isn't necessarily the product being
        # added to the basket. For child products, it is the *parent* product
        # that gets passed to the form. An optional product_id param is passed
        # to indicate the ID of the child product being added to the basket.
        self.basket = basket
        self.parent_product = product

        super(AddToBasketForm, self).__init__(*args, **kwargs)

        # Dynamically build fields
        if product.is_parent:
            self.my_create_parent_product_fields(product)
        self._create_product_fields(product)

    # Dynamic form building methods

    def my_create_parent_product_fields(self, product):
        """
        Adds the fields for a "group"-type product (eg, a parent product with a
        list of children.

        Currently requires that a stock record exists for the children
        """
        choices = []
        disabled_values = []
        for child in product.children.all():
            # Build a description of the child, including any pertinent
            # attributes
            attr_summary = child.attribute_summary
            if attr_summary:
                summary = attr_summary
            else:
                summary = child.get_title()

            # Check if it is available to buy
            info = self.basket.strategy.fetch_for_product(child)
            if not info.availability.is_available_to_buy:
                disabled_values.append(child.id)

            choices.append((child.id, summary))

        self.fields['child_id'] = forms.ChoiceField(
            choices=tuple(choices), label=_("Variant"),
            widget=forms.RadioSelect
        )

0 个答案:

没有答案