update
This commit is contained in:
26
core/apps/api/models/ad/variant.py
Normal file
26
core/apps/api/models/ad/variant.py
Normal file
@@ -0,0 +1,26 @@
|
||||
from django.db import models
|
||||
from django_core.models.base import AbstractBaseModel
|
||||
from django.utils.translation import gettext_lazy as _
|
||||
from django.core.validators import MinValueValidator
|
||||
|
||||
|
||||
class AdVariantModel(AbstractBaseModel):
|
||||
ad = models.ForeignKey("api.AdModel", on_delete=models.CASCADE, related_name="variants", verbose_name=_("Ad"))
|
||||
color = models.ForeignKey(
|
||||
"api.ColorModel", on_delete=models.CASCADE, verbose_name=_("Color"), null=True, blank=False
|
||||
)
|
||||
size = models.ForeignKey("api.SizeModel", on_delete=models.CASCADE, verbose_name=_("Size"), null=True, blank=False)
|
||||
is_available = models.BooleanField(_("Is Available"), default=True)
|
||||
price = models.DecimalField(_("Price"), max_digits=10, decimal_places=2, validators=[MinValueValidator(0)])
|
||||
stock_quantity = models.PositiveIntegerField(_("Stock Quantity"), default=0)
|
||||
|
||||
def __str__(self):
|
||||
return f"{self.color} - {self.size}"
|
||||
|
||||
class Meta:
|
||||
db_table = "ad_variant"
|
||||
verbose_name = _("Ad Variant")
|
||||
verbose_name_plural = _("Ad Variants")
|
||||
indexes = [
|
||||
models.Index(fields=["ad", "is_available"]),
|
||||
]
|
||||
Reference in New Issue
Block a user