Skip to content

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

Add available_for_purchase product field

IKarbowiake5659b15d882
diff --git a/saleor/product/migrations/0122_product_available_for_purchase.py b/saleor/product/migrations/0122_product_available_for_purchase.py
new file mode 100644
index 0000000000..e86fac6592
--- /dev/null
+++ b/saleor/product/migrations/0122_product_available_for_purchase.py
@@ -0,0 +1,30 @@
+# Generated by Django 3.1 on 2020-08-18 09:19
+import datetime
+
+from django.db import migrations, models
+
+
+def set_all_published_products_as_available_for_purchase(apps, schema_editor):
+ Product = apps.get_model("product", "Product")
+ Product.objects.filter(is_published=True).update(
+ available_for_purchase=datetime.datetime.today()
+ )
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ("product", "0121_auto_20200810_1415"),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name="product",
+ name="available_for_purchase",
+ field=models.DateField(blank=True, null=True),
+ ),
+ migrations.RunPython(
+ set_all_published_products_as_available_for_purchase,
+ migrations.RunPython.noop,
+ ),
+ ]
diff --git a/saleor/product/models.py b/saleor/product/models.py
index 9604624dc8..c4312a57bb 100644
--- a/saleor/product/models.py
+++ b/saleor/product/models.py
@@ -264,6 +264,7 @@ class Product(SeoModel, ModelWithMetadata, PublishableModel):
weight = MeasurementField(
measurement=Weight, unit_choices=WeightUnits.CHOICES, blank=True, null=True
)
+ available_for_purchase = models.DateField(blank=True, null=True)
objects = ProductsQueryset.as_manager()
translated = TranslationProxy()