Saleor Core: the high performance, composable, headless commerce API.
Python cartcheckoutcommercecomposablee-commerceecommercegraphqlheadlessheadless-commercemultichannelomsorder-managementpaymentspimpythonshopshopping-cartstore
* Shorten line in models if possible
akjanikb351534f09a6
diff --git a/saleor/cart/models.py b/saleor/cart/models.pyindex 223708120c..eb9e2ce380 100644--- a/saleor/cart/models.py+++ b/saleor/cart/models.py@@ -83,27 +83,21 @@ class Cart(models.Model):status = models.CharField(max_length=32, choices=CartStatus.CHOICES, default=CartStatus.OPEN)- created = models.DateTimeField(- auto_now_add=True)- last_status_change = models.DateTimeField(- auto_now_add=True)+ created = models.DateTimeField(auto_now_add=True)+ last_status_change = models.DateTimeField(auto_now_add=True)user = models.ForeignKey(settings.AUTH_USER_MODEL, blank=True, null=True, related_name='carts',on_delete=models.CASCADE)- email = models.EmailField(- blank=True, null=True)- token = models.UUIDField(- primary_key=True, default=uuid4, editable=False)+ email = models.EmailField(blank=True, null=True)+ token = models.UUIDField(primary_key=True, default=uuid4, editable=False)voucher = models.ForeignKey('discount.Voucher', null=True, related_name='+',on_delete=models.SET_NULL)- checkout_data = JSONField(- null=True, editable=False,)+ checkout_data = JSONField(null=True, editable=False)total = PriceField(currency=settings.DEFAULT_CURRENCY, max_digits=12, decimal_places=2,default=0)- quantity = models.PositiveIntegerField(- default=0)+ quantity = models.PositiveIntegerField(default=0)objects = CartQueryset.as_manager()@@ -247,8 +241,7 @@ class CartLine(models.Model, ItemLine):'product.ProductVariant', related_name='+', on_delete=models.CASCADE)quantity = models.PositiveIntegerField(validators=[MinValueValidator(0), MaxValueValidator(999)])- data = JSONField(- blank=True, default={})+ data = JSONField(blank=True, default={})class Meta:unique_together = ('cart', 'variant', 'data')diff --git a/saleor/dashboard/category/forms.py b/saleor/dashboard/category/forms.pyindex 1c69804432..46a1657728 100644--- a/saleor/dashboard/category/forms.py+++ b/saleor/dashboard/category/forms.py@@ -22,16 +22,16 @@ class CategoryForm(forms.ModelForm):labels = {'name': pgettext_lazy('Category field',- 'category name'),+ 'Name'),'description': pgettext_lazy('Category field',- 'category description'),+ 'Description'),'is_hidden': pgettext_lazy('Category field','Hide in navigation'),'parent': pgettext_lazy('Category field',- 'category parent')}+ 'Category parent')}def save(self, commit=True):self.instance.slug = slugify(unidecode(self.instance.name))diff --git a/saleor/dashboard/discount/forms.py b/saleor/dashboard/discount/forms.pyindex fddaa56169..59ec064414 100644--- a/saleor/dashboard/discount/forms.py+++ b/saleor/dashboard/discount/forms.py@@ -27,7 +27,7 @@ class SaleForm(forms.ModelForm):'Sale name'),'type': pgettext_lazy('Sale form label',- 'Type of products related to the sale'),+ 'Fixed or percentage'),'value': pgettext_lazy('Sale form label','Sale value'),@@ -192,7 +192,7 @@ class ProductVoucherForm(CommonVoucherForm):'Country'),'product': pgettext_lazy('Shipping voucher form label',- 'product'),+ 'Product'),}def __init__(self, *args, **kwargs):@@ -212,7 +212,7 @@ class CategoryVoucherForm(CommonVoucherForm):'Country'),'category': pgettext_lazy('Category voucher form label',- 'category'),+ 'Category'),}def __init__(self, *args, **kwargs):diff --git a/saleor/dashboard/staff/forms.py b/saleor/dashboard/staff/forms.pyindex e65ddf3aa2..16676a52f0 100644--- a/saleor/dashboard/staff/forms.py+++ b/saleor/dashboard/staff/forms.py@@ -25,4 +25,3 @@ class StaffForm(forms.ModelForm):'Staff form label', 'Active'),'is_staff': pgettext_lazy('Staff form label', 'Staff')}-diff --git a/saleor/discount/models.py b/saleor/discount/models.pyindex 82db35dc38..b8664ec4c5 100644--- a/saleor/discount/models.py+++ b/saleor/discount/models.py@@ -87,24 +87,17 @@ class Voucher(models.Model):type = models.CharField(max_length=20, choices=TYPE_CHOICES, default=VALUE_TYPE)- name = models.CharField(- max_length=255, null=True, blank=True)- code = models.CharField(- max_length=12, unique=True, db_index=True)- usage_limit = models.PositiveIntegerField(- null=True, blank=True)- used = models.PositiveIntegerField(- default=0, editable=False)- start_date = models.DateField(- default=date.today)- end_date = models.DateField(- null=True, blank=True)+ name = models.CharField(max_length=255, null=True, blank=True)+ code = models.CharField(max_length=12, unique=True, db_index=True)+ usage_limit = models.PositiveIntegerField(null=True, blank=True)+ used = models.PositiveIntegerField(default=0, editable=False)+ start_date = models.DateField(default=date.today)+ end_date = models.DateField(null=True, blank=True)discount_value_type = models.CharField(max_length=10, choices=DISCOUNT_VALUE_TYPE_CHOICES,default=DISCOUNT_VALUE_FIXED)- discount_value = models.DecimalField(- max_digits=12, decimal_places=2)+ discount_value = models.DecimalField(max_digits=12, decimal_places=2)# not mandatory fields, usage depends on typeproduct = models.ForeignKey(@@ -113,8 +106,7 @@ class Voucher(models.Model):'product.Category', blank=True, null=True, on_delete=models.CASCADE)apply_to = models.CharField(max_length=20, blank=True, null=True)- limit = PriceField(- max_digits=12, decimal_places=2, null=True,+ limit = PriceField(max_digits=12, decimal_places=2, null=True,blank=True, currency=settings.DEFAULT_CURRENCY)objects = VoucherQueryset.as_manager()@@ -263,12 +255,9 @@ class Sale(models.Model):name = models.CharField(max_length=255)type = models.CharField(max_length=10, choices=DISCOUNT_TYPE_CHOICES, default=FIXED)- value = models.DecimalField(- max_digits=12, decimal_places=2, default=0)- products = models.ManyToManyField(- 'product.Product', blank=True)- categories = models.ManyToManyField(- 'product.Category', blank=True)+ value = models.DecimalField(max_digits=12, decimal_places=2, default=0)+ products = models.ManyToManyField('product.Product', blank=True)+ categories = models.ManyToManyField('product.Category', blank=True)class Meta:app_label = 'discount'diff --git a/saleor/order/models.py b/saleor/order/models.pyindex 7862f55993..88cd79afb5 100644--- a/saleor/order/models.py+++ b/saleor/order/models.py@@ -55,11 +55,9 @@ class Order(models.Model, ItemSet):user_email = models.EmailField(blank=True, default='', editable=False)shipping_price = PriceField(- pgettext_lazy('Order field', 'shipping price'),currency=settings.DEFAULT_CURRENCY, max_digits=12, decimal_places=4,default=0, editable=False)- token = models.CharField(- max_length=36, unique=True)+ token = models.CharField(max_length=36, unique=True)total_net = PriceField(currency=settings.DEFAULT_CURRENCY, max_digits=12, decimal_places=2,blank=True, null=True)@@ -71,8 +69,7 @@ class Order(models.Model, ItemSet):discount_amount = PriceField(currency=settings.DEFAULT_CURRENCY, max_digits=12, decimal_places=2,blank=True, null=True)- discount_name = models.CharField(- max_length=255, default='', blank=True)+ discount_name = models.CharField(max_length=255, default='', blank=True)objects = OrderQuerySet.as_manager()@@ -200,10 +197,8 @@ class DeliveryGroup(models.Model, ItemSet):Order, related_name='groups', editable=False, on_delete=models.CASCADE)shipping_method_name = models.CharField(max_length=255, null=True, default=None, blank=True, editable=False)- tracking_number = models.CharField(- max_length=255, default='', blank=True)- last_updated = models.DateTimeField(- null=True, auto_now=True)+ tracking_number = models.CharField(max_length=255, default='', blank=True)+ last_updated = models.DateTimeField(null=True, auto_now=True)def __str__(self):return pgettext_lazy(@@ -244,21 +239,15 @@ class OrderLine(models.Model, ItemLine):product = models.ForeignKey(Product, blank=True, null=True, related_name='+',on_delete=models.SET_NULL)- product_name = models.CharField(- max_length=128)- product_sku = models.CharField(- max_length=32)- stock_location = models.CharField(- max_length=100,- default='')+ product_name = models.CharField(max_length=128)+ product_sku = models.CharField(max_length=32)+ stock_location = models.CharField(max_length=100, default='')stock = models.ForeignKey('product.Stock', on_delete=models.SET_NULL, null=True)quantity = models.IntegerField(validators=[MinValueValidator(0), MaxValueValidator(999)])- unit_price_net = models.DecimalField(- max_digits=12, decimal_places=4)- unit_price_gross = models.DecimalField(- max_digits=12, decimal_places=4)+ unit_price_net = models.DecimalField(max_digits=12, decimal_places=4)+ unit_price_gross = models.DecimalField(max_digits=12, decimal_places=4)def __str__(self):return self.product_name@@ -331,15 +320,11 @@ class Payment(BasePayment):class OrderHistoryEntry(models.Model):- date = models.DateTimeField(- default=now, editable=False)+ date = models.DateTimeField(default=now, editable=False)order = models.ForeignKey(- Order, related_name='history',- on_delete=models.CASCADE)- status = models.CharField(- max_length=32, choices=OrderStatus.CHOICES)- comment = models.CharField(- max_length=100, default='', blank=True)+ Order, related_name='history', on_delete=models.CASCADE)+ status = models.CharField(max_length=32, choices=OrderStatus.CHOICES)+ comment = models.CharField(max_length=100, default='', blank=True)user = models.ForeignKey(settings.AUTH_USER_MODEL, blank=True, null=True,on_delete=models.SET_NULL)@@ -359,8 +344,7 @@ class OrderNote(models.Model):date = models.DateTimeField(auto_now_add=True)order = models.ForeignKey(Order, related_name='notes', on_delete=models.CASCADE)- content = models.CharField(- max_length=250)+ content = models.CharField(max_length=250)def __str__(self):return pgettext_lazy(diff --git a/saleor/product/models.py b/saleor/product/models.pyindex 002e2ac553..d01c6a27f5 100644--- a/saleor/product/models.py+++ b/saleor/product/models.py@@ -63,16 +63,13 @@ class Category(MPTTModel):class ProductClass(models.Model):- name = models.CharField(- max_length=128)- has_variants = models.BooleanField(- default=True)+ name = models.CharField(max_length=128)+ has_variants = models.BooleanField(default=True)product_attributes = models.ManyToManyField('ProductAttribute', related_name='products_class', blank=True)variant_attributes = models.ManyToManyField('ProductAttribute', related_name='product_variants_class', blank=True)- is_shipping_required = models.BooleanField(- default=False)+ is_shipping_required = models.BooleanField(default=False)class Meta:app_label = 'product'@@ -96,25 +93,17 @@ class ProductManager(models.Manager):class Product(models.Model, ItemRange):product_class = models.ForeignKey(- ProductClass, related_name='products',- on_delete=models.CASCADE)- name = models.CharField(- max_length=128)+ ProductClass, related_name='products', on_delete=models.CASCADE)+ name = models.CharField(max_length=128)description = models.TextField()- categories = models.ManyToManyField(- Category, related_name='products')+ categories = models.ManyToManyField(Category, related_name='products')price = PriceField(currency=settings.DEFAULT_CURRENCY, max_digits=12, decimal_places=2)- available_on = models.DateField(- blank=True, null=True)- is_published = models.BooleanField(- default=True)- attributes = HStoreField(- default={})- updated_at = models.DateTimeField(- auto_now=True, null=True)- is_featured = models.BooleanField(- default=False)+ available_on = models.DateField(blank=True, null=True)+ is_published = models.BooleanField(default=True)+ attributes = HStoreField(default={})+ updated_at = models.DateTimeField(auto_now=True, null=True)+ is_featured = models.BooleanField(default=False)objects = ProductManager()@@ -197,21 +186,15 @@ class Product(models.Model, ItemRange):class ProductVariant(models.Model, Item):- sku = models.CharField(- max_length=32,- unique=True)- name = models.CharField(- max_length=100,- blank=True)+ sku = models.CharField(max_length=32, unique=True)+ name = models.CharField(max_length=100, blank=True)price_override = PriceField(currency=settings.DEFAULT_CURRENCY, max_digits=12, decimal_places=2,blank=True, null=True)product = models.ForeignKey(Product, related_name='variants', on_delete=models.CASCADE)- attributes = HStoreField(- default={})- images = models.ManyToManyField(- 'ProductImage', through='VariantImage')+ attributes = HStoreField(default={})+ images = models.ManyToManyField('ProductImage', through='VariantImage')class Meta:app_label = 'product'@@ -328,8 +311,7 @@ class StockManager(models.Manager):class Stock(models.Model):variant = models.ForeignKey(- ProductVariant, related_name='stock',- on_delete=models.CASCADE)+ ProductVariant, related_name='stock', on_delete=models.CASCADE)location = models.ForeignKey(StockLocation, null=True, on_delete=models.CASCADE)quantity = models.IntegerField(@@ -355,10 +337,8 @@ class Stock(models.Model):class ProductAttribute(models.Model):- slug = models.SlugField(- max_length=50, unique=True)- name = models.CharField(- max_length=100)+ slug = models.SlugField(max_length=50, unique=True)+ name = models.CharField(max_length=100)class Meta:ordering = ('slug', )@@ -374,13 +354,11 @@ class ProductAttribute(models.Model):class AttributeChoiceValue(models.Model):- name = models.CharField(- max_length=100)+ name = models.CharField(max_length=100)slug = models.SlugField()color = models.CharField(- max_length=7,- validators=[RegexValidator('^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$')],- blank=True)+ max_length=7, blank=True,+ validators=[RegexValidator('^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$')])attribute = models.ForeignKey(ProductAttribute, related_name='values', on_delete=models.CASCADE)@@ -401,15 +379,12 @@ class ImageManager(models.Manager):class ProductImage(models.Model):product = models.ForeignKey(- Product, related_name='images',- on_delete=models.CASCADE)+ Product, related_name='images', on_delete=models.CASCADE)image = VersatileImageField(upload_to='products', ppoi_field='ppoi', blank=False)ppoi = PPOIField()- alt = models.CharField(- max_length=128, blank=True)- order = models.PositiveIntegerField(- editable=False)+ alt = models.CharField(max_length=128, blank=True)+ order = models.PositiveIntegerField(editable=False)objects = ImageManager()diff --git a/saleor/shipping/models.py b/saleor/shipping/models.pyindex 2c318c6f7d..41cb6531d1 100644--- a/saleor/shipping/models.py+++ b/saleor/shipping/models.py@@ -16,10 +16,8 @@ COUNTRY_CODE_CHOICES = [(ANY_COUNTRY, ANY_COUNTRY_DISPLAY)] + list(countries)class ShippingMethod(models.Model):- name = models.CharField(- max_length=100)- description = models.TextField(- blank=True, default='')+ name = models.CharField(max_length=100)+ description = models.TextField(blank=True, default='')class Meta:permissions = (diff --git a/saleor/site/models.py b/saleor/site/models.pyindex 249457fcb3..339c7a0e5b 100644--- a/saleor/site/models.py+++ b/saleor/site/models.py@@ -11,11 +11,8 @@ patch_contrib_sites()class SiteSettings(models.Model):site = models.OneToOneField(Site, related_name='settings', on_delete=models.CASCADE)- header_text = models.CharField(- max_length=200, blank=True)- description = models.CharField(- max_length=500,- blank=True)+ header_text = models.CharField(max_length=200, blank=True)+ description = models.CharField(max_length=500, blank=True)class Meta:permissions = (@@ -36,8 +33,7 @@ class SiteSettings(models.Model):class AuthorizationKey(models.Model):site_settings = models.ForeignKey(SiteSettings, on_delete=models.CASCADE)name = models.CharField(- max_length=20,- choices=AuthenticationBackends.BACKENDS)+ max_length=20, choices=AuthenticationBackends.BACKENDS)key = models.TextField()password = models.TextField()diff --git a/saleor/userprofile/models.py b/saleor/userprofile/models.pyindex 508a6edbff..9acb346e9f 100644--- a/saleor/userprofile/models.py+++ b/saleor/userprofile/models.py@@ -48,27 +48,17 @@ class AddressManager(models.Manager):class Address(models.Model):- first_name = models.CharField(- max_length=256, blank=True)- last_name = models.CharField(- max_length=256, blank=True)- company_name = models.CharField(- max_length=256, blank=True)- street_address_1 = models.CharField(- max_length=256, blank=True)- street_address_2 = models.CharField(- max_length=256, blank=True)- city = models.CharField(- max_length=256, blank=True)- city_area = models.CharField(- max_length=128, blank=True)- postal_code = models.CharField(- max_length=20, blank=True)+ first_name = models.CharField(max_length=256, blank=True)+ last_name = models.CharField(max_length=256, blank=True)+ company_name = models.CharField(max_length=256, blank=True)+ street_address_1 = models.CharField(max_length=256, blank=True)+ street_address_2 = models.CharField(max_length=256, blank=True)+ city = models.CharField(max_length=256, blank=True)+ city_area = models.CharField(max_length=128, blank=True)+ postal_code = models.CharField(max_length=20, blank=True)country = CountryField()- country_area = models.CharField(- max_length=128, blank=True)- phone = PossiblePhoneNumberField(- blank=True, default='')+ country_area = models.CharField(max_length=128, blank=True)+ phone = PossiblePhoneNumberField(blank=True, default='')objects = AddressManager()@property@@ -112,16 +102,11 @@ class UserManager(BaseUserManager):class User(PermissionsMixin, AbstractBaseUser):- email = models.EmailField(- unique=True)- addresses = models.ManyToManyField(- Address, blank=True)- is_staff = models.BooleanField(- default=False)- is_active = models.BooleanField(- default=True)- date_joined = models.DateTimeField(- default=timezone.now, editable=False)+ email = models.EmailField(unique=True)+ addresses = models.ManyToManyField(Address, blank=True)+ is_staff = models.BooleanField(default=False)+ is_active = models.BooleanField(default=True)+ date_joined = models.DateTimeField(default=timezone.now, editable=False)default_shipping_address = models.ForeignKey(Address, related_name='+', null=True, blank=True,on_delete=models.SET_NULL)