52 lines
2.4 KiB
Python
52 lines
2.4 KiB
Python
from django.contrib.gis.db import models
|
|
|
|
from tagulous.models import SingleTagField, TagField
|
|
|
|
from companies.models import Company
|
|
|
|
# Create your models here.
|
|
|
|
class Product(models.Model):
|
|
|
|
SYNCHRONIZED = 'SYNCHRONIZED'
|
|
IMPORTED = 'IMPORTED'
|
|
MANUAL = 'MANUAL'
|
|
|
|
SOURCES = (
|
|
(SYNCHRONIZED, 'Sincronizado'),
|
|
(IMPORTED, 'Importado'),
|
|
(MANUAL, 'Manual'),
|
|
)
|
|
|
|
company = models.ForeignKey(Company, on_delete=models.DO_NOTHING, null=True, blank=True)
|
|
sku = models.CharField('Referencia de producto', max_length=255, null=True, blank=True )
|
|
name = models.CharField('Nombre del producto', max_length=500, null=True, blank=True)
|
|
description = models.TextField('Descripción', null=True, blank=True)
|
|
image = models.ImageField('Imagen del producto', upload_to='products/', null=True, blank=True)
|
|
url = models.URLField('URL del producto', null=True, blank=True)
|
|
price = models.DecimalField('Precio', max_digits=10, decimal_places=2, null=True, blank=True)
|
|
shipping_cost = models.DecimalField('Gastos de envío', max_digits=10, decimal_places=2, null=True, blank=True)
|
|
shipping_terms = models.TextField('Condiciones de envío', null=True, blank=True)
|
|
source = models.CharField('Fuente', choices=SOURCES, max_length=25, null=True, blank=True)
|
|
sourcing_date = models.DateTimeField('Fecha de importación original de producto', null=True, blank=True)
|
|
update_date = models.DateTimeField('Fecha de actualización de producto', null=True, blank=True)
|
|
discount = models.DecimalField('Descuento', max_digits=5, decimal_places=2, null=True, blank=True)
|
|
stock = models.PositiveIntegerField('Stock', null=True)
|
|
tags = TagField(force_lowercase=True,max_count=5, tree=True)
|
|
category = SingleTagField(null=True) # main tag category
|
|
attributes = TagField(force_lowercase=True,max_count=5, tree=True)
|
|
identifiers = models.TextField('Identificador único de producto', null=True, blank=True)
|
|
|
|
# internal
|
|
created = models.DateTimeField('date of creation', auto_now_add=True)
|
|
updated = models.DateTimeField('date last update', auto_now=True)
|
|
creator = models.ForeignKey('core.CustomUser', on_delete=models.DO_NOTHING, null=True, related_name='product')
|
|
# history = models.FoiregnKey('history.History', on_delete=models.DO_NOTHING, null=True)
|
|
|
|
def __str__(self):
|
|
return f"{self.name} / {self.sku}"
|
|
|
|
class Meta:
|
|
verbose_name = "Producto"
|
|
verbose_name_plural = "Productos"
|