Пример #1
0
    def __init__(self, **kwargs):
        self.request = kwargs.pop('request', None)
        super(ProductBaseForm, self).__init__(**kwargs)
        self.fields["sales_unit"].required = True  # TODO: Move this to model
        self.fields["type"].required = True
        if self.instance.pk:
            del self.fields["file"]

        self.fields["manufacturer"] = Select2ModelField(
            required=False,
            initial=(self.instance.manufacturer if self.instance.pk else None),
            model=Manufacturer,
            widget=QuickAddManufacturerSelect(
                initial=(self.instance.manufacturer if self.instance.pk else None),
                editable_model="shuup.Manufacturer",
                attrs={"data-placeholder": ugettext("Select a manufacturer")}
            )
        )
        if self.instance.pk:
            initial_type = self.instance.type
        else:
            initial_type = kwargs.get("initial", {}).get("type")

        self.fields["type"] = Select2ModelField(
            label=_("Product type"),
            initial=initial_type,
            model=ProductType,
            widget=QuickAddProductTypeSelect(
                editable_model="shuup.ProductType",
                initial=initial_type
            )
        )
Пример #2
0
 class Meta:
     model = Product
     fields = (
         "accounting_identifier",
         "barcode",
         "cost_center",
         "depth",
         "gross_weight",
         "gtin",
         "height",
         "manufacturer",
         "net_weight",
         "profit_center",
         "sales_unit",
         "shipping_mode",
         "sku",
         "stock_behavior",
         "tax_class",
         "type",
         "width",
         # I18n
         "description",
         "short_description",
         "keywords",
         "name",
         "slug",
         "status_text",
         "variation_name",
     )
     widgets = {
         "keywords":
         forms.TextInput(),
         "sales_unit":
         QuickAddSalesUnitSelect(editable_model="shuup.SalesUnit"),
         "tax_class":
         QuickAddTaxClassSelect(editable_model="shuup.TaxClass"),
         "type":
         QuickAddProductTypeSelect(editable_model="shuup.ProductType"),
         "manufacturer":
         QuickAddManufacturerSelect(editable_model="shuup.Manufacturer"),
         "description":
         TextEditorWidget(),
         "short_description":
         forms.TextInput(),
     }