some parts of product - fix custom pagination - add id to pages list
This commit is contained in:
94
apps/product/models.py
Normal file
94
apps/product/models.py
Normal file
@@ -0,0 +1,94 @@
|
||||
from django.db import models
|
||||
from apps.core.models import BaseModel
|
||||
|
||||
|
||||
# Create your models here.
|
||||
|
||||
class ReferenceProduct(BaseModel):
|
||||
""" Reference product - like: rice """
|
||||
|
||||
name = models.CharField(max_length=250, default='empty') # noqa
|
||||
type_choices = (
|
||||
('F', 'Free'), # free product
|
||||
('G', 'Governmental') # government product
|
||||
)
|
||||
type = models.CharField(max_length=3, choices=type_choices)
|
||||
img = models.CharField(max_length=100, default='empty')
|
||||
|
||||
def __str__(self):
|
||||
return f'name: {self.name} - type: {self.type}'
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
super(ReferenceProduct, self).save(*args, **kwargs)
|
||||
|
||||
|
||||
class Product(BaseModel):
|
||||
""" Child of reference product - like: brown rice """
|
||||
name = models.CharField(max_length=250, default='empty') # noqa
|
||||
type_choices = (
|
||||
('F', 'Free'), # free product
|
||||
('G', 'Governmental') #
|
||||
)
|
||||
type = models.CharField(max_length=3, choices=type_choices)
|
||||
img = models.CharField(max_length=100, default='empty')
|
||||
reference = models.ForeignKey(
|
||||
ReferenceProduct,
|
||||
on_delete=models.CASCADE,
|
||||
related_name='reference_product',
|
||||
null=True
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return f'name: {self.name} - type: {self.type}'
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
super(Product, self).save(*args, **kwargs)
|
||||
|
||||
|
||||
class Attribute(BaseModel):
|
||||
"""
|
||||
every reference product have multiple attributes
|
||||
"""
|
||||
reference_product = models.ForeignKey(
|
||||
ReferenceProduct,
|
||||
on_delete=models.CASCADE,
|
||||
related_name='reference_attribute',
|
||||
null=True
|
||||
)
|
||||
name = models.CharField(max_length=100, default='empty')
|
||||
type = models.CharField(
|
||||
max_length=255,
|
||||
default='empty',
|
||||
help_text='type of attribute like: calculate product by kilogram'
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return f'{self.reference_product.name} - {self.name}'
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
return super(Attribute, self).save(*args, **kwargs)
|
||||
|
||||
|
||||
class AttributeValue(BaseModel):
|
||||
"""
|
||||
every child product should have attribute value for
|
||||
reference product attribute
|
||||
"""
|
||||
product = models.ForeignKey(
|
||||
Product,
|
||||
on_delete=models.CASCADE,
|
||||
related_name='product_attribute_value',
|
||||
null=True
|
||||
)
|
||||
attribute = models.ForeignKey(
|
||||
Attribute,
|
||||
on_delete=models.CASCADE,
|
||||
related_name='attribute_value'
|
||||
)
|
||||
value = models.IntegerField(default=0)
|
||||
|
||||
def __str__(self):
|
||||
return f'{self.product.name} - {self.attribute.name} - {self.value}'
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
return super(AttributeValue, self).save(*args, **kwargs)
|
||||
Reference in New Issue
Block a user