mirror of
https://github.com/welton89/RRBEC.git
synced 2026-04-05 13:35:42 +00:00
refactor: clean up product models, remove deployment files, and add media static serving configuration
This commit is contained in:
@@ -4,11 +4,14 @@ from django.contrib.auth.models import User
|
||||
from categories.models import Categories
|
||||
|
||||
|
||||
|
||||
class UnitOfMeasure(models.Model):
|
||||
id = models.AutoField(primary_key=True)
|
||||
name = models.CharField(max_length=50, unique=True, help_text="Ex: 'Unidade', 'Kg', 'Litro'")
|
||||
abbreviation = models.CharField(max_length=10, unique=True, help_text="Ex: 'un', 'kg', 'L'")
|
||||
name = models.CharField(
|
||||
max_length=50, unique=True, help_text="Ex: 'Unidade', 'Kg', 'Litro'"
|
||||
)
|
||||
abbreviation = models.CharField(
|
||||
max_length=10, unique=True, help_text="Ex: 'un', 'kg', 'L'"
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return self.abbreviation
|
||||
@@ -19,7 +22,7 @@ class Product(models.Model):
|
||||
id = models.AutoField(primary_key=True)
|
||||
name = models.CharField(max_length=100)
|
||||
description = models.TextField(null=True, blank=True)
|
||||
image = models.ImageField(null=True, blank=True)
|
||||
image = models.ImageField(upload_to="products/%Y/%m/%d/", null=True, blank=True)
|
||||
price = models.DecimalField(max_digits=10, decimal_places=2)
|
||||
quantity = models.IntegerField(null=False, default=0)
|
||||
category = models.ForeignKey(Categories, on_delete=models.CASCADE)
|
||||
@@ -27,54 +30,48 @@ class Product(models.Model):
|
||||
active = models.BooleanField(default=True)
|
||||
unit_of_measure = models.ForeignKey(
|
||||
UnitOfMeasure,
|
||||
on_delete=models.SET_NULL, # Define como NULL se a unidade de medida for excluída
|
||||
on_delete=models.SET_NULL, # Define como NULL se a unidade de medida for excluída
|
||||
null=True,
|
||||
blank=True,
|
||||
help_text="Unidade de medida para este produto."
|
||||
help_text="Unidade de medida para este produto.",
|
||||
)
|
||||
|
||||
# Campo de composição (mantido da resposta anterior)
|
||||
components = models.ManyToManyField(
|
||||
'self',
|
||||
through='ProductComponent',
|
||||
through_fields=('composite_product', 'component_product'),
|
||||
"self",
|
||||
through="ProductComponent",
|
||||
through_fields=("composite_product", "component_product"),
|
||||
symmetrical=False,
|
||||
related_name='is_component_of'
|
||||
related_name="is_component_of",
|
||||
)
|
||||
|
||||
|
||||
def __str__(self) -> str:
|
||||
return f"{self.name}"
|
||||
|
||||
|
||||
|
||||
class ProductComponent(models.Model):
|
||||
composite_product = models.ForeignKey(
|
||||
Product,
|
||||
on_delete=models.CASCADE,
|
||||
related_name='composition_entries',
|
||||
help_text="O produto que é composto por outros produtos."
|
||||
related_name="composition_entries",
|
||||
help_text="O produto que é composto por outros produtos.",
|
||||
)
|
||||
component_product = models.ForeignKey(
|
||||
Product,
|
||||
on_delete=models.CASCADE,
|
||||
related_name='used_as_component_in',
|
||||
help_text="Um produto que é componente de outro produto."
|
||||
related_name="used_as_component_in",
|
||||
help_text="Um produto que é componente de outro produto.",
|
||||
)
|
||||
quantity_required = models.PositiveIntegerField(
|
||||
default=1,
|
||||
help_text="Quantidade deste componente necessária para o produto composto."
|
||||
help_text="Quantidade deste componente necessária para o produto composto.",
|
||||
)
|
||||
|
||||
class Meta:
|
||||
unique_together = ('composite_product', 'component_product')
|
||||
unique_together = ("composite_product", "component_product")
|
||||
|
||||
def __str__(self):
|
||||
return (
|
||||
f"{self.composite_product.name} requer "
|
||||
f"{self.quantity_required} de {self.component_product.name}"
|
||||
)
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
Reference in New Issue
Block a user