38695-vm/core/models.py
Flatlogic Bot 03bf5cace7 1.1
2026-02-22 21:23:39 +00:00

39 lines
1.7 KiB
Python
Raw Permalink Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

from django.db import models
class Product(models.Model):
STOCK_STATUS_CHOICES = [
('instock', 'В наявності'),
('outofstock', 'Немає в наявності'),
]
wp_id = models.CharField(max_length=50, unique=True, verbose_name="ID WordPress")
image = models.URLField(max_length=500, blank=True, null=True, verbose_name="Фото")
name = models.CharField(max_length=255, verbose_name="Назва товару")
sku = models.CharField(max_length=100, blank=True, null=True, verbose_name="Артикул (SKU)")
price = models.DecimalField(max_digits=12, decimal_places=2, verbose_name="Ціна (грн)")
stock_status = models.CharField(max_length=20, choices=STOCK_STATUS_CHOICES, verbose_name="Статус")
total_sales = models.IntegerField(default=0, verbose_name="Продано")
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
def __str__(self):
return self.name
class Meta:
verbose_name = "Товар"
verbose_name_plural = "Товари"
ordering = ['-total_sales']
class Variation(models.Model):
product = models.ForeignKey(Product, on_delete=models.CASCADE, related_name='variations', verbose_name="Основний товар")
size = models.CharField(max_length=50, verbose_name="Розмір")
price = models.DecimalField(max_digits=12, decimal_places=2, verbose_name="Ціна варіації")
stock_quantity = models.IntegerField(default=0, verbose_name="Залишок на складі")
def __str__(self):
return f"{self.product.name} - {self.size}"
class Meta:
verbose_name = "Варіація"
verbose_name_plural = "Варіації"