Skip to content

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

Add Product and Category models.

Michal Ociepkaba4e93d7729e
diff --git a/product/models.py b/product/models.py
index 71a8362390..54578dec87 100755
--- a/product/models.py
+++ b/product/models.py
@@ -1,3 +1,35 @@
from django.db import models
+from django.utils.translation import pgettext as _
+from django_prices.models import PriceField
+from satchless.util.models import Subtyped
+from satchless.item import ItemRange
+from mptt.models import MPTTModel
-# Create your models here.
+
+class Category(MPTTModel):
+
+ name = models.CharField(_('Category field', 'name'), max_length=128)
+ slug = models.SlugField(_('Category field', 'slug'), max_length=50,
+ unique=True)
+ description = models.TextField(_('Category field', 'description'),
+ blank=True)
+ parent = models.ForeignKey('self', null=True, related_name='children',
+ blank=True,
+ verbose_name=_('Category field', 'parent'))
+
+ def __unicode__(self):
+ return self.name
+
+
+class Product(Subtyped, ItemRange):
+
+ name = models.CharField(_('Product field', 'name'), max_length=128)
+ slug = models.SlugField(_('Product field', 'slug'), max_length=50,
+ unique=True)
+ price = PriceField(_('Product field', 'price'), currency='USD',
+ max_digits=12, decimal_places=4)
+ category = models.ForeignKey(Category,
+ verbose_name=_('Product field', 'category'))
+
+ def __unicode__(self):
+ return self.name
diff --git a/saleor/settings.py b/saleor/settings.py
index f5d6828c13..7c891631c6 100644
--- a/saleor/settings.py
+++ b/saleor/settings.py
@@ -78,7 +78,7 @@ INSTALLED_APPS = (
# External apps
'south',
# Local apps
- 'saleor',
+ 'product',
)
LOGGING = {
@@ -125,3 +125,5 @@ LOGGING = {
}
WARN_ABOUT_INVALID_HTML5_OUTPUT = True
+
+SATCHLESS_DEFAULT_CURRENCY = 'USD'