Skip to content

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

Use HStore field for attributes

Marcin Gębala4ed51c49e18a
diff --git a/saleor/product/migrations/0013_auto_20161130_0608.py b/saleor/product/migrations/0013_auto_20161130_0608.py
new file mode 100644
index 0000000000..79c346510b
--- /dev/null
+++ b/saleor/product/migrations/0013_auto_20161130_0608.py
@@ -0,0 +1,17 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.10.3 on 2016-11-30 12:08
+from __future__ import unicode_literals
+
+from django.db import migrations
+from django.contrib.postgres.operations import HStoreExtension
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('product', '0012_auto_20160218_0812'),
+ ]
+
+ operations = [
+ HStoreExtension()
+ ]
diff --git a/saleor/product/migrations/0014_remove_productvariant_attributes.py b/saleor/product/migrations/0014_remove_productvariant_attributes.py
new file mode 100644
index 0000000000..55a47f2694
--- /dev/null
+++ b/saleor/product/migrations/0014_remove_productvariant_attributes.py
@@ -0,0 +1,19 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.10.3 on 2016-11-30 12:22
+from __future__ import unicode_literals
+
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('product', '0013_auto_20161130_0608'),
+ ]
+
+ operations = [
+ migrations.RemoveField(
+ model_name='productvariant',
+ name='attributes',
+ ),
+ ]
diff --git a/saleor/product/migrations/0015_productvariant_attributes.py b/saleor/product/migrations/0015_productvariant_attributes.py
new file mode 100644
index 0000000000..bf2f6eda75
--- /dev/null
+++ b/saleor/product/migrations/0015_productvariant_attributes.py
@@ -0,0 +1,21 @@
+# -*- coding: utf-8 -*-
+# Generated by Django 1.10.3 on 2016-11-30 12:26
+from __future__ import unicode_literals
+
+import django.contrib.postgres.fields.hstore
+from django.db import migrations
+
+
+class Migration(migrations.Migration):
+
+ dependencies = [
+ ('product', '0014_remove_productvariant_attributes'),
+ ]
+
+ operations = [
+ migrations.AddField(
+ model_name='productvariant',
+ name='attributes',
+ field=django.contrib.postgres.fields.hstore.HStoreField(default='', verbose_name='attributes'),
+ ),
+ ]
diff --git a/saleor/product/models/base.py b/saleor/product/models/base.py
index d125d89d05..9a4ea02b64 100644
--- a/saleor/product/models/base.py
+++ b/saleor/product/models/base.py
@@ -13,6 +13,7 @@ from django.utils.encoding import python_2_unicode_compatible, smart_text
from django.utils.text import slugify
from django.utils.translation import pgettext_lazy
from django_prices.models import PriceField
+from django.contrib.postgres.fields import HStoreField
from mptt.managers import TreeManager
from mptt.models import MPTTModel
from satchless.item import InsufficientStock, Item, ItemRange
@@ -189,8 +190,8 @@ class ProductVariant(models.Model, Item):
unit=settings.DEFAULT_WEIGHT, max_digits=6, decimal_places=2,
blank=True, null=True)
product = models.ForeignKey(Product, related_name='variants')
- attributes = HStoreField(pgettext_lazy('Variant field', 'attributes'),
- default={})
+ attributes = HStoreField(
+ pgettext_lazy('Variant field', 'attributes'), default='')
images = models.ManyToManyField('ProductImage', through='VariantImage')
class Meta: