Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
Add stock field in the Product model
Michal Ociepka935e05971944
diff --git a/product/migrations/0002_auto__add_field_product_stock.py b/product/migrations/0002_auto__add_field_product_stock.pynew file mode 100644index 0000000000..2964bd78a5--- /dev/null+++ b/product/migrations/0002_auto__add_field_product_stock.py@@ -0,0 +1,46 @@+# -*- coding: utf-8 -*-+import datetime+from south.db import db+from south.v2 import SchemaMigration+from django.db import models+++class Migration(SchemaMigration):++ def forwards(self, orm):+ # Adding field 'Product.stock'+ db.add_column(u'product_product', 'stock',+ self.gf('django.db.models.fields.DecimalField')(default='1', max_digits=10, decimal_places=4),+ keep_default=False)+++ def backwards(self, orm):+ # Deleting field 'Product.stock'+ db.delete_column(u'product_product', 'stock')+++ models = {+ u'product.category': {+ 'Meta': {'object_name': 'Category'},+ 'description': ('django.db.models.fields.TextField', [], {'blank': 'True'}),+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),+ 'level': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),+ 'lft': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '128'}),+ 'parent': ('django.db.models.fields.related.ForeignKey', [], {'blank': 'True', 'related_name': "'children'", 'null': 'True', 'to': u"orm['product.Category']"}),+ 'rght': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'}),+ 'slug': ('django.db.models.fields.SlugField', [], {'unique': 'True', 'max_length': '50'}),+ 'tree_id': ('django.db.models.fields.PositiveIntegerField', [], {'db_index': 'True'})+ },+ u'product.product': {+ 'Meta': {'object_name': 'Product'},+ 'category': ('django.db.models.fields.related.ForeignKey', [], {'to': u"orm['product.Category']"}),+ u'id': ('django.db.models.fields.AutoField', [], {'primary_key': 'True'}),+ 'name': ('django.db.models.fields.CharField', [], {'max_length': '128'}),+ 'price': ('django_prices.models.PriceField', [], {'currency': "'USD'", 'max_digits': '12', 'decimal_places': '4'}),+ 'stock': ('django.db.models.fields.DecimalField', [], {'default': "'1'", 'max_digits': '10', 'decimal_places': '4'}),+ 'subtype_attr': ('django.db.models.fields.CharField', [], {'max_length': '500'})+ }+ }++ complete_apps = ['product']\ No newline at end of filediff --git a/product/models.py b/product/models.pyindex 1806d35bcc..0b00e7e596 100644--- a/product/models.py+++ b/product/models.py@@ -1,9 +1,10 @@+from decimal import Decimalfrom django.db import modelsfrom django.utils.safestring import mark_safefrom django.utils.translation import pgettext as _from django_prices.models import PriceFieldfrom mptt.models import MPTTModel-from satchless.item import ItemRange+from satchless.item import Itemfrom satchless.util.models import Subtypedfrom unidecode import unidecodeimport re@@ -24,23 +25,29 @@ class Category(MPTTModel):return self.name-class Product(Subtyped, ItemRange):+class Product(Subtyped, Item):name = models.CharField(_('Product field', 'name'), max_length=128)price = PriceField(_('Product field', 'price'), currency='USD',max_digits=12, decimal_places=4)category = models.ForeignKey(Category, related_name='products',verbose_name=_('Product field', 'category'))+ stock = models.DecimalField(_('Product item field','stock'),+ max_digits=10, decimal_places=4,+ default=Decimal(1))def __unicode__(self):return self.name- @models.permalink- def get_absolute_url(self):- return ('product:details', [self.get_slug(), self.id])-def get_slug(self):value = unidecode(self.name)value = re.sub(r'[^\w\s-]', '', value).strip().lower()return mark_safe(re.sub(r'[-\s]+', '-', value))++ def get_price_per_item(self, **kwargs):+ return self.price++ @models.permalink+ def get_absolute_url(self):+ return ('product:details', [self.get_slug(), self.id])diff --git a/saleor/static/less/style.less b/saleor/static/less/style.lessindex 6fdb28ed36..95a635f389 100644--- a/saleor/static/less/style.less+++ b/saleor/static/less/style.less@@ -1 +1,5 @@@import "bootstrap/bootstrap.less";++.navbar {+ margin-bottom: 50px;+}