product price refactor , admin display name, product models verbose names
This commit is contained in:
+13
-10
@@ -6,7 +6,7 @@ import requests
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
|
||||
class MainCategoryModel(models.Model):
|
||||
name = models.CharField(max_length=50, verbose_name='نام')
|
||||
name = models.CharField(max_length=50, verbose_name='نام دسته بندی')
|
||||
slug = models.SlugField(max_length=50, unique=True, help_text="اسم دسته را برای مسیر به انگلیسی و بدون فاصله وارد کنید")
|
||||
icon = models.ImageField(upload_to='category_model/',verbose_name='آیکون', blank=True, null=True)
|
||||
meta_title = models.CharField(max_length=60, verbose_name="عنوان متا", help_text="عنوان متا برای SEO", blank=True, null=True)
|
||||
@@ -26,7 +26,7 @@ class MainCategoryModel(models.Model):
|
||||
|
||||
|
||||
class SubCategoryModel(models.Model):
|
||||
name = models.CharField(max_length=50, verbose_name='نام')
|
||||
name = models.CharField(max_length=50, verbose_name='نام دسته بندی')
|
||||
slug = models.SlugField(max_length=50, unique=True, help_text="اسم دسته را برای مسیر به انگلیسی و بدون فاصله وارد کنید")
|
||||
image = models.ImageField(upload_to='category_model/',verbose_name='عکس', blank=True, null=True)
|
||||
icon = models.ImageField(upload_to='category_model/',verbose_name='آیکون', blank=True, null=True)
|
||||
@@ -107,12 +107,12 @@ class ProductModel(models.Model):
|
||||
discount = models.SmallIntegerField(default=0, verbose_name='تخفیف')
|
||||
slug = models.SlugField(max_length=50, unique=True, blank=True, null=True, allow_unicode=True,
|
||||
verbose_name='نام یکتا', help_text="این فیلد را خالی بگذارید")
|
||||
meta_description = models.CharField(max_length=300, blank=True, null=True, help_text='این فیلد را حتما پر کنید')
|
||||
meta_keywords = models.CharField(max_length=300, blank=True, null=True, help_text='این فیلد را حتما پر کنید')
|
||||
meta_rating = models.FloatField(default=5, help_text='امتیاز محصول')
|
||||
meta_description = models.CharField(max_length=300, blank=True, null=True, help_text='این فیلد را حتما پر کنید', verbose_name='متا دیسکریپشن')
|
||||
meta_keywords = models.CharField(max_length=300, blank=True, null=True, help_text='این فیلد را حتما پر کنید', verbose_name='متا کیورد')
|
||||
meta_rating = models.FloatField(default=5, help_text='امتیاز محصول', verbose_name='متا ریتینگ')
|
||||
created_at = models.DateTimeField(auto_now_add=True, verbose_name='زمان ثبت محصول')
|
||||
category = models.ForeignKey(SubCategoryModel, null=True, on_delete=models.SET_NULL, related_name='products', verbose_name='دسته بندی محصول')
|
||||
related_products = models.ManyToManyField('self', blank=True,)
|
||||
related_products = models.ManyToManyField('self', blank=True, verbose_name='محصولات مرتبط')
|
||||
def format_discount_price(self):
|
||||
discount_price = int(self.price * (100 - self.discount) / 100)
|
||||
formatted_num = "{:,.0f}".format(discount_price)
|
||||
@@ -122,9 +122,11 @@ class ProductModel(models.Model):
|
||||
def __str__(self):
|
||||
return self.name
|
||||
|
||||
def get_toman_price(self):
|
||||
dollor_object, _ = DollorModel.objects.get_or_create(unique_filed='unique')
|
||||
dollor_price = dollor_object.price
|
||||
def get_toman_price(self, dollor_price=None):
|
||||
if not dollor_price:
|
||||
dollor_object, _ = DollorModel.objects.get_or_create(unique_filed='unique')
|
||||
dollor_price = dollor_object.price
|
||||
|
||||
dollar_to_dirham = 0.27
|
||||
if dollor_price is None:
|
||||
raise ValidationError({"dollor_price": "The 'dollor_price' must be provided in the context for dollar pricing."})
|
||||
@@ -134,6 +136,7 @@ class ProductModel(models.Model):
|
||||
toman_price = self.price * dollor_price
|
||||
elif self.currency == 'derham':
|
||||
toman_price = self.price * dollor_price * dollar_to_dirham
|
||||
toman_price = toman_price if toman_price > self.min_price else self.min_price
|
||||
return toman_price
|
||||
|
||||
def get_toman_price_after_discount(self):
|
||||
@@ -152,7 +155,7 @@ class ProductModel(models.Model):
|
||||
class InStuckColors(models.Model):
|
||||
color = models.CharField(_("رنگ"), null=True, blank=True, max_length=255)
|
||||
in_stuck = models.PositiveIntegerField(default=0, verbose_name="تعداد موجود")
|
||||
product = models.ForeignKey(ProductModel, on_delete=models.CASCADE, related_name='colors')
|
||||
product = models.ForeignKey(ProductModel, on_delete=models.CASCADE, related_name='colors', verbose_name='محصول')
|
||||
class Meta:
|
||||
verbose_name = 'تعداد موجود رنگ'
|
||||
verbose_name_plural = 'تعداد موجود رنگ ها'
|
||||
|
||||
Reference in New Issue
Block a user