Skip to content

Saleor Core: the high performance, composable, headless commerce API.

Allow to create product without category and set published field to 'False' as default

IKarbowiak6f44abf9abf1
diff --git a/saleor/core/models.py b/saleor/core/models.py
index cc349d16ff..07c4037e87 100644
--- a/saleor/core/models.py
+++ b/saleor/core/models.py
@@ -57,7 +57,7 @@ class PublishedQuerySet(models.QuerySet):
class PublishableModel(models.Model):
publication_date = models.DateField(blank=True, null=True)
- is_published = models.BooleanField(default=True)
+ is_published = models.BooleanField(default=False)
objects = PublishedQuerySet.as_manager()
diff --git a/saleor/graphql/schema.graphql b/saleor/graphql/schema.graphql
index 4d12f342c1..7b618ddab9 100644
--- a/saleor/graphql/schema.graphql
+++ b/saleor/graphql/schema.graphql
@@ -2860,7 +2860,7 @@ type Product implements Node {
name: String!
description: String!
descriptionJson: JSONString!
- category: Category!
+ category: Category
updatedAt: DateTime
chargeTaxes: Boolean!
weight: Weight
diff --git a/saleor/page/migrations/0009_auto_20191108_0402.py b/saleor/page/migrations/0009_auto_20191108_0402.py
new file mode 100644
index 0000000000..1149f6f0e0
--- /dev/null
+++ b/saleor/page/migrations/0009_auto_20191108_0402.py
@@ -0,0 +1,16 @@
+# Generated by Django 2.2.6 on 2019-11-08 10:02
+
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [("page", "0008_raw_html_to_json")]
+
+ operations = [
+ migrations.AlterField(
+ model_name="page",
+ name="is_published",
+ field=models.BooleanField(default=False),
+ )
+ ]
diff --git a/saleor/product/migrations/0110_auto_20191108_0340.py b/saleor/product/migrations/0110_auto_20191108_0340.py
new file mode 100644
index 0000000000..3d9b63d011
--- /dev/null
+++ b/saleor/product/migrations/0110_auto_20191108_0340.py
@@ -0,0 +1,33 @@
+# Generated by Django 2.2.6 on 2019-11-08 09:40
+
+import django.db.models.deletion
+from django.db import migrations, models
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [("product", "0109_auto_20191006_1433")]
+
+ operations = [
+ migrations.AlterField(
+ model_name="collection",
+ name="is_published",
+ field=models.BooleanField(default=False),
+ ),
+ migrations.AlterField(
+ model_name="product",
+ name="category",
+ field=models.ForeignKey(
+ blank=True,
+ null=True,
+ on_delete=django.db.models.deletion.SET_NULL,
+ related_name="products",
+ to="product.Category",
+ ),
+ ),
+ migrations.AlterField(
+ model_name="product",
+ name="is_published",
+ field=models.BooleanField(default=False),
+ ),
+ ]
diff --git a/saleor/product/models.py b/saleor/product/models.py
index 1f712dc0ce..d475d599a5 100644
--- a/saleor/product/models.py
+++ b/saleor/product/models.py
@@ -253,7 +253,11 @@ class Product(SeoModel, ModelWithMetadata, PublishableModel):
blank=True, default=dict, sanitizer=clean_draft_js
)
category = models.ForeignKey(
- Category, related_name="products", on_delete=models.CASCADE
+ Category,
+ related_name="products",
+ on_delete=models.SET_NULL,
+ null=True,
+ blank=True,
)
currency = models.CharField(