Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Allow to create product without category in dashboard and add validation for 'is_published' field
IKarbowiak8e87cac9fec3
diff --git a/saleor/dashboard/product/forms.py b/saleor/dashboard/product/forms.pyindex 57bc62389f..96030f69af 100644--- a/saleor/dashboard/product/forms.py+++ b/saleor/dashboard/product/forms.py@@ -1,6 +1,7 @@import bleachfrom django import formsfrom django.conf import settings+from django.core.exceptions import ValidationErrorfrom django.db import transactionfrom django.db.models import Countfrom django.forms.models import ModelChoiceIterator@@ -264,7 +265,9 @@ class ProductForm(MoneyModelForm, AttributesMixin):),)category = TreeNodeChoiceField(- queryset=Category.objects.all(), label=pgettext_lazy("Category", "Category")+ required=False,+ queryset=Category.objects.all(),+ label=pgettext_lazy("Category", "Category"),)collections = forms.ModelMultipleChoiceField(required=False,@@ -363,6 +366,13 @@ class ProductForm(MoneyModelForm, AttributesMixin):)return seo_description+ def clean_is_published(self):+ is_published = self.cleaned_data["is_published"]+ category = self.data["category"]+ if not category and is_published:+ raise ValidationError("You must add cateogry to publish product")+ return is_published+def save(self, commit=True):assert commit is True, "Commit is required to build the M2M structure"