Skip to content

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

Add labels meta attribute in dashboard product ModelForms

akjanik1fc297586ae7
diff --git a/saleor/dashboard/order/forms.py b/saleor/dashboard/order/forms.py
index 855c4e3cfc..4f732e1250 100644
--- a/saleor/dashboard/order/forms.py
+++ b/saleor/dashboard/order/forms.py
@@ -296,7 +296,7 @@ class ChangeStockForm(forms.ModelForm):
fields = ['stock']
labels = {
'stock': pgettext_lazy(
- 'Ordered line field', 'Stock amount')}
+ 'Change stock form label', 'Stock amount')}
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
diff --git a/saleor/dashboard/product/forms.py b/saleor/dashboard/product/forms.py
index 23c4e0f63d..309f745a0a 100644
--- a/saleor/dashboard/product/forms.py
+++ b/saleor/dashboard/product/forms.py
@@ -27,6 +27,14 @@ class StockForm(forms.ModelForm):
class Meta:
model = Stock
exclude = ['quantity_allocated', 'variant']
+ labels = {
+ 'location': pgettext_lazy(
+ 'Stock form label', 'location'),
+ 'quantity': pgettext_lazy(
+ 'Stock form label', 'quantity'),
+ 'cost_price': pgettext_lazy(
+ 'Stock form label', 'cost price'),
+ }
def __init__(self, *args, **kwargs):
self.variant = kwargs.pop('variant')
@@ -54,12 +62,21 @@ class ProductClassForm(forms.ModelForm):
model = ProductClass
exclude = []
labels = {
+ 'name': pgettext_lazy(
+ 'Product class form label',
+ 'Product class name'),
+ 'has_variants': pgettext_lazy(
+ 'Product class form label',
+ 'Check if product has more than one variant'),
'variant_attributes': pgettext_lazy(
'Product class form label',
'Attributes specific to each variant'),
'product_attributes': pgettext_lazy(
'Product class form label',
- 'Attributes common to all variants')}
+ 'Attributes common to all variants'),
+ 'is_shipping_required': pgettext_lazy(
+ 'Product class form label',
+ 'Require shipping')}
def clean(self):
data = super().clean()
@@ -100,9 +117,16 @@ class ProductForm(forms.ModelForm):
model = Product
exclude = ['attributes', 'product_class']
labels = {
- 'is_published': pgettext_lazy('product form', 'Published'),
+ 'name': pgettext_lazy('Product form label', 'Name'),
+ 'description': pgettext_lazy('Product form label', 'Description'),
+ 'categories': pgettext_lazy('Product form label', 'Categories'),
+ 'price': pgettext_lazy('Product form label', 'Price'),
+ 'available_on': pgettext_lazy(
+ 'Product form label', 'Product availabilty'),
+ 'updated_at': pgettext_lazy('Product form label', 'Last update'),
+ 'is_published': pgettext_lazy('Product form label', 'Published'),
'is_featured': pgettext_lazy(
- 'product form', 'Feature this product on homepage')}
+ 'Product form label', 'Feature this product on homepage')}
def __init__(self, *args, **kwargs):
self.product_attributes = []
@@ -149,6 +173,11 @@ class ProductVariantForm(forms.ModelForm):
class Meta:
model = ProductVariant
exclude = ['attributes', 'product', 'images']
+ labels = {
+ 'sku': pgettext_lazy('Product variant form label', 'SKU'),
+ 'price_override': pgettext_lazy(
+ 'Product variant form label', 'Override price'),
+ 'name': pgettext_lazy('Product variant form label', 'Name')}
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
@@ -232,6 +261,10 @@ class ProductImageForm(forms.ModelForm):
class Meta:
model = ProductImage
exclude = ('product', 'order')
+ labels = {
+ 'image': pgettext_lazy('Product image form label', 'Image'),
+ 'alt': pgettext_lazy(
+ 'Product image form label', 'Short description')}
def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
@@ -263,12 +296,20 @@ class ProductAttributeForm(forms.ModelForm):
class Meta:
model = ProductAttribute
exclude = []
+ labels = {
+ 'name': pgettext_lazy(
+ 'Product attribute form label', 'Display name'),
+ 'slug': pgettext_lazy(
+ 'Product attribute form label', 'Internal name')}
class StockLocationForm(forms.ModelForm):
class Meta:
model = StockLocation
exclude = []
+ labels = {
+ 'name': pgettext_lazy(
+ 'Stock location form label', 'Stock location')}
class AttributeChoiceValueForm(forms.ModelForm):
@@ -276,6 +317,13 @@ class AttributeChoiceValueForm(forms.ModelForm):
model = AttributeChoiceValue
fields = ['attribute', 'name', 'color']
widgets = {'attribute': forms.widgets.HiddenInput()}
+ labels = {
+ 'name': pgettext_lazy(
+ 'Attribute choice value form label', 'Display name'),
+ 'name': pgettext_lazy(
+ 'Attribute choice value form label', 'Attribute'),
+ 'color': pgettext_lazy(
+ 'Attribute choice value form label', 'Color')}
def save(self, commit=True):
self.instance.slug = slugify(self.instance.name)
@@ -313,6 +361,8 @@ class UploadImageForm(forms.ModelForm):
class Meta:
model = ProductImage
fields = ('image', )
+ labels = {
+ 'image': pgettext_lazy('Upload image form label', 'Image')}
def __init__(self, *args, **kwargs):
product = kwargs.pop('product')
diff --git a/saleor/product/models.py b/saleor/product/models.py
index bfcbf68cd2..495a9fbce4 100644
--- a/saleor/product/models.py
+++ b/saleor/product/models.py
@@ -64,15 +64,14 @@ class Category(MPTTModel):
class ProductClass(models.Model):
name = models.CharField(
- pgettext_lazy('Product class field', 'name'), max_length=128)
+ max_length=128)
has_variants = models.BooleanField(
- pgettext_lazy('Product class field', 'has variants'), default=True)
+ 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(
- pgettext_lazy('Product class field', 'is shipping required'),
default=False)
class Meta:
@@ -100,23 +99,22 @@ class Product(models.Model, ItemRange):
ProductClass, related_name='products',
on_delete=models.CASCADE)
name = models.CharField(
- pgettext_lazy('Product field', 'name'), max_length=128)
+ max_length=128)
description = models.TextField()
categories = models.ManyToManyField(
Category, related_name='products')
price = PriceField(
- pgettext_lazy('Product field', 'price'),
currency=settings.DEFAULT_CURRENCY, max_digits=12, decimal_places=2)
available_on = models.DateField(
- pgettext_lazy('Product field', 'available on'), blank=True, null=True)
+ blank=True, null=True)
is_published = models.BooleanField(
- pgettext_lazy('Product field', 'is published'), default=True)
+ default=True)
attributes = HStoreField(
- pgettext_lazy('Product field', 'attributes'), default={})
+ default={})
updated_at = models.DateTimeField(
- pgettext_lazy('Product field', 'updated at'), auto_now=True, null=True)
+ auto_now=True, null=True)
is_featured = models.BooleanField(
- pgettext_lazy('Product field', 'is featured'), default=False)
+ default=False)
objects = ProductManager()
@@ -200,19 +198,18 @@ class Product(models.Model, ItemRange):
class ProductVariant(models.Model, Item):
sku = models.CharField(
- pgettext_lazy('Product variant field', 'SKU'), max_length=32,
+ max_length=32,
unique=True)
name = models.CharField(
- pgettext_lazy('Product variant field', 'variant name'), max_length=100,
+ max_length=100,
blank=True)
price_override = PriceField(
- pgettext_lazy('Product variant field', 'price override'),
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(
- pgettext_lazy('Product variant field', 'attributes'), default={})
+ default={})
images = models.ManyToManyField(
'ProductImage', through='VariantImage')
@@ -299,8 +296,7 @@ class ProductVariant(models.Model, Item):
class StockLocation(models.Model):
- name = models.CharField(
- pgettext_lazy('Stock location field', 'location'), max_length=100)
+ name = models.CharField(max_length=100)
class Meta:
permissions = (
@@ -337,13 +333,11 @@ class Stock(models.Model):
location = models.ForeignKey(
StockLocation, null=True, on_delete=models.CASCADE)
quantity = models.IntegerField(
- pgettext_lazy('Stock item field', 'quantity'),
validators=[MinValueValidator(0)], default=Decimal(1))
quantity_allocated = models.IntegerField(
pgettext_lazy('Stock item field', 'allocated quantity'),
validators=[MinValueValidator(0)], default=Decimal(0))
cost_price = PriceField(
- pgettext_lazy('Stock item field', 'cost price'),
currency=settings.DEFAULT_CURRENCY, max_digits=12, decimal_places=2,
blank=True, null=True)
@@ -363,10 +357,8 @@ class Stock(models.Model):
class ProductAttribute(models.Model):
slug = models.SlugField(
- pgettext_lazy('Product attribute field', 'internal name'),
max_length=50, unique=True)
name = models.CharField(
- pgettext_lazy('Product attribute field', 'display name'),
max_length=100)
class Meta:
@@ -384,11 +376,9 @@ class ProductAttribute(models.Model):
class AttributeChoiceValue(models.Model):
name = models.CharField(
- pgettext_lazy('Attribute choice value field', 'display name'),
max_length=100)
slug = models.SlugField()
color = models.CharField(
- pgettext_lazy('Attribute choice value field', 'color'),
max_length=7,
validators=[RegexValidator('^#([A-Fa-f0-9]{6}|[A-Fa-f0-9]{3})$')],
blank=True)
@@ -418,7 +408,6 @@ class ProductImage(models.Model):
upload_to='products', ppoi_field='ppoi', blank=False)
ppoi = PPOIField()
alt = models.CharField(
- pgettext_lazy('Product image field', 'short description'),
max_length=128, blank=True)
order = models.PositiveIntegerField(
pgettext_lazy('Product image field', 'order'), editable=False)