Database modeling for products and store The Next CEO of Stack OverflowGUI for products and ordersModeling a Mage character from nWoD, using DjangoDatabase schema for a products and bugs aggregatorCameleonica: key value storeStoring database references to files/mediaCivil status database with DjangoImage Database ServiceDjango social network application - database schemaStore nested json repsonses in relational databaseIsolate a Database Change Within Django Transaction.Atomic
What steps are necessary to read a Modern SSD in Medieval Europe?
Yu-Gi-Oh cards in Python 3
Man transported from Alternate World into ours by a Neutrino Detector
Raspberry pi 3 B with Ubuntu 18.04 server arm64: what chip
Point distance program written without a framework
Is it ok to trim down a tube patch?
How can I make proper oatmeal cookies?
"Eavesdropping" vs "Listen in on"
Is fine stranded wire ok for main supply line?
Reshaping json / reparing json inside shell script (remove trailing comma)
Do I need to write [sic] when including a quotation with a number less than 10 that isn't written out?
Is there an equivalent of cd - for cp or mv
IC has pull-down resistors on SMBus lines?
Can this note be analyzed as a non-chord tone?
Film where the government was corrupt with aliens, people sent to kill aliens are given rigged visors not showing the right aliens
(How) Could a medieval fantasy world survive a magic-induced "nuclear winter"?
Is it okay to majorly distort historical facts while writing a fiction story?
Defamation due to breach of confidentiality
What would be the main consequences for a country leaving the WTO?
What connection does MS Office have to Netscape Navigator?
Why don't programming languages automatically manage the synchronous/asynchronous problem?
Traveling with my 5 year old daughter (as the father) without the mother from Germany to Mexico
Which Pokemon have a special animation when running with them out of their pokeball?
Why do we say 'Un seul M' and not 'Une seule M' even though M is a "consonne"
Database modeling for products and store
The Next CEO of Stack OverflowGUI for products and ordersModeling a Mage character from nWoD, using DjangoDatabase schema for a products and bugs aggregatorCameleonica: key value storeStoring database references to files/mediaCivil status database with DjangoImage Database ServiceDjango social network application - database schemaStore nested json repsonses in relational databaseIsolate a Database Change Within Django Transaction.Atomic
$begingroup$
I am planning to develop a virtual shopping mall where stores of any kind can be registered, such as in a physical shopping mall. First I want to develop an efficient and effective database modeling for products and stores only. I wanted it be very flexible and user friendly. Here is the model design for Product
and Store
. How can I improve the database design?
My concern is mainly for the categories be user friendly. For example Men -> Clothing -> Shirts
as a category. If you wish, you can help me to improve the design as well, I would appreciate all recommendations.
I am using Python 3 and Django 1.11.
DAY = (( 'Sun', 'Sunday'),
( 'Mon', 'Monday'),
( 'Tue', 'Tuesday'),
( 'Wed', 'Wednesday'),
( 'Thu', 'Thursday'),
( 'Fri', 'Friday'),
( 'Sat', 'Saturday')
)
class OpeningHours(models.Model):
store = models.ForeignKey('Store', related_name="opening_hour")
weekday = models.CharField(choices=DAY, max_length=12)
opening_hour = models.TimeField()
closing_hour = models.TimeField()
class Meta:
verbose_name = 'Opening Hour'
verbose_name_plural = 'Opening Hours'
def ___str__(self):
return ' - '.format(self.weekday, str(self.opening_hour), str(self.closing_hour))
class Store(models.Model):
merchant = models.ForeignKey(User, blank=True, null=False)
token = models.CharField(default=token_generator, max_length=20, unique=True, editable=False)
name_of_legal_entity = models.CharField(max_length=250, blank=False, null=False)
pan_number = models.CharField(max_length=20, blank=False, null=False)
registered_office_address = models.CharField(max_length=200)
name_of_store = models.CharField(max_length=100)
email = models.EmailField(blank=False, null=False)
store_contact_number = models.PositiveIntegerField(blank=False, null=False)
# store_long = models.DecimalField(max_digits=12, decimal_places=8, null=True)
# store_lat = models.DecimalField(max_digits=12, decimal_places=8, null=True)
is_active = models.BooleanField(default=True)
class Meta:
verbose_name = 'Store'
def __str__(self):
return self.name_of_store
class Meta:
verbose_name = 'Store'
verbose_name_plural = 'Stores'
class Product(models.Model):
store = models.ForeignKey(Store)
token = models.CharField(default=token_generator, max_length=20, unique=True, editable=False)
category = models.ForeignKey('CatalogCategory', related_name='products')
brand = models.ForeignKey('Brand', related_name="product_brand")
image = models.ImageField(upload_to='products/images/')
name_of_product = models.CharField(max_length=120, blank=False,null=False)
description = models.TextField(blank=False,null=False)
price = models.DecimalField(decimal_places=2, max_digits=20)
discount = models.DecimalField(decimal_places=2, max_digits=20)
sales_price = models.DecimalField(decimal_places=2, max_digits=20)
is_active = models.BooleanField(default=True)
is_gurantee_available = models.BooleanField(default=False)
is_negotiated = models.BooleanField(default=False)
is_verified = models.BooleanField(default=False)
is_instock = models.BooleanField(default=False)
def __str__(self):
return self.name_of_product
class Meta:
verbose_name = 'Product'
verbose_name_plural = 'Products'
class Brand(models.Model):
name = models.CharField(max_length=100, blank=True, null=True)
logo = models.ImageField(upload_to='products/brand/images/')
class Meta:
verbose_name = 'Brand'
verbose_name_plural = 'Brands'
def __str__(self):
return self.name
class Variation(models.Model):
VAR_CATEGORIES = (
('size', 'size'),
('color', 'color'),
)
product = models.ForeignKey(Product)
token = models.CharField(default=token_generator, max_length=20, unique=True, editable=False)
category = models.CharField(max_length=10, choices=VAR_CATEGORIES)
title = models.CharField(max_length=50)
price = models.DecimalField(decimal_places=2, max_digits=20)
discount = models.DecimalField(blank=True ,null =True, decimal_places=2, max_digits=20)
active = models.BooleanField(default=True)
quantity = models.IntegerField(null=True , blank=True)
sales_price = models.DecimalField(blank=True ,null =True, decimal_places=2, max_digits=20)
image = models.ImageField(upload_to='products/images/')
class Meta:
verbose_name = 'Variation'
verbose_name_plural = 'Variations'
def __str__(self):
return '0 of 1 from 2' .format(self.product.name_of_product, self.title, self.product.store.name_of_store)
class CatalogCategory(models.Model):
token = models.CharField(default=token_generator, max_length=20, unique=True, editable=False)
parent = models.ForeignKey('self', blank=True, null=True, related_name='children')
name = models.CharField(max_length=300)
description = models.TextField(blank=True)
class Meta:
verbose_name = 'CatalogCategory'
verbose_name_plural = 'CatalogCategories'
def __str__(self):
return self.name
class ProductImage(models.Model):
product = models.ForeignKey(Product, null=True, blank=True, related_name="product_image")
image = models.ImageField(upload_to='products/images/')
updated = models.DateTimeField(auto_now_add=False, auto_now=True)
@property
def imageName(self):
return str(os.path.basename(self.image.name))
def __str__(self):
return str(self.image)
class Meta:
verbose_name = 'Product Image'
verbose_name_plural = 'Product Images'
class StoreCategory(models.Model):
STORE_CATEGORIES= (
('GROCERY', ('Grocery')),
('MEATS', ('Meats')),
('FOODS & BEVERAGES', ('Foods')),
('COMPUTERS', ('Computers')),
('ELECTRONICS', ('Electronics')),
('HOME & OUTDOOR', ('Home & Outdoor')),
('FASHION & BEAUTY', ('Fashion & Beauty')),
('HEALTH', ('Health')),
('SPORTS & FITNESS', ('Sports & Fitness')),
('BABY', ('Baby')),
('BOOKS', ('Books')),
)
product = models.ForeignKey(Product,null=True, on_delete=models.CASCADE)
store_category = models.CharField(choices=STORE_CATEGORIES, default='GROCERY', max_length=30)
# objects = VariationManager()
class Meta:
verbose_name = 'Store Category'
verbose_name_plural = 'Store Categories'
def __str__(self):
# return str(self.product.name_of_product)
return '0 of category 1' .format(self.product.name_of_product, str(self.store_category))
python python-3.x database django
$endgroup$
add a comment |
$begingroup$
I am planning to develop a virtual shopping mall where stores of any kind can be registered, such as in a physical shopping mall. First I want to develop an efficient and effective database modeling for products and stores only. I wanted it be very flexible and user friendly. Here is the model design for Product
and Store
. How can I improve the database design?
My concern is mainly for the categories be user friendly. For example Men -> Clothing -> Shirts
as a category. If you wish, you can help me to improve the design as well, I would appreciate all recommendations.
I am using Python 3 and Django 1.11.
DAY = (( 'Sun', 'Sunday'),
( 'Mon', 'Monday'),
( 'Tue', 'Tuesday'),
( 'Wed', 'Wednesday'),
( 'Thu', 'Thursday'),
( 'Fri', 'Friday'),
( 'Sat', 'Saturday')
)
class OpeningHours(models.Model):
store = models.ForeignKey('Store', related_name="opening_hour")
weekday = models.CharField(choices=DAY, max_length=12)
opening_hour = models.TimeField()
closing_hour = models.TimeField()
class Meta:
verbose_name = 'Opening Hour'
verbose_name_plural = 'Opening Hours'
def ___str__(self):
return ' - '.format(self.weekday, str(self.opening_hour), str(self.closing_hour))
class Store(models.Model):
merchant = models.ForeignKey(User, blank=True, null=False)
token = models.CharField(default=token_generator, max_length=20, unique=True, editable=False)
name_of_legal_entity = models.CharField(max_length=250, blank=False, null=False)
pan_number = models.CharField(max_length=20, blank=False, null=False)
registered_office_address = models.CharField(max_length=200)
name_of_store = models.CharField(max_length=100)
email = models.EmailField(blank=False, null=False)
store_contact_number = models.PositiveIntegerField(blank=False, null=False)
# store_long = models.DecimalField(max_digits=12, decimal_places=8, null=True)
# store_lat = models.DecimalField(max_digits=12, decimal_places=8, null=True)
is_active = models.BooleanField(default=True)
class Meta:
verbose_name = 'Store'
def __str__(self):
return self.name_of_store
class Meta:
verbose_name = 'Store'
verbose_name_plural = 'Stores'
class Product(models.Model):
store = models.ForeignKey(Store)
token = models.CharField(default=token_generator, max_length=20, unique=True, editable=False)
category = models.ForeignKey('CatalogCategory', related_name='products')
brand = models.ForeignKey('Brand', related_name="product_brand")
image = models.ImageField(upload_to='products/images/')
name_of_product = models.CharField(max_length=120, blank=False,null=False)
description = models.TextField(blank=False,null=False)
price = models.DecimalField(decimal_places=2, max_digits=20)
discount = models.DecimalField(decimal_places=2, max_digits=20)
sales_price = models.DecimalField(decimal_places=2, max_digits=20)
is_active = models.BooleanField(default=True)
is_gurantee_available = models.BooleanField(default=False)
is_negotiated = models.BooleanField(default=False)
is_verified = models.BooleanField(default=False)
is_instock = models.BooleanField(default=False)
def __str__(self):
return self.name_of_product
class Meta:
verbose_name = 'Product'
verbose_name_plural = 'Products'
class Brand(models.Model):
name = models.CharField(max_length=100, blank=True, null=True)
logo = models.ImageField(upload_to='products/brand/images/')
class Meta:
verbose_name = 'Brand'
verbose_name_plural = 'Brands'
def __str__(self):
return self.name
class Variation(models.Model):
VAR_CATEGORIES = (
('size', 'size'),
('color', 'color'),
)
product = models.ForeignKey(Product)
token = models.CharField(default=token_generator, max_length=20, unique=True, editable=False)
category = models.CharField(max_length=10, choices=VAR_CATEGORIES)
title = models.CharField(max_length=50)
price = models.DecimalField(decimal_places=2, max_digits=20)
discount = models.DecimalField(blank=True ,null =True, decimal_places=2, max_digits=20)
active = models.BooleanField(default=True)
quantity = models.IntegerField(null=True , blank=True)
sales_price = models.DecimalField(blank=True ,null =True, decimal_places=2, max_digits=20)
image = models.ImageField(upload_to='products/images/')
class Meta:
verbose_name = 'Variation'
verbose_name_plural = 'Variations'
def __str__(self):
return '0 of 1 from 2' .format(self.product.name_of_product, self.title, self.product.store.name_of_store)
class CatalogCategory(models.Model):
token = models.CharField(default=token_generator, max_length=20, unique=True, editable=False)
parent = models.ForeignKey('self', blank=True, null=True, related_name='children')
name = models.CharField(max_length=300)
description = models.TextField(blank=True)
class Meta:
verbose_name = 'CatalogCategory'
verbose_name_plural = 'CatalogCategories'
def __str__(self):
return self.name
class ProductImage(models.Model):
product = models.ForeignKey(Product, null=True, blank=True, related_name="product_image")
image = models.ImageField(upload_to='products/images/')
updated = models.DateTimeField(auto_now_add=False, auto_now=True)
@property
def imageName(self):
return str(os.path.basename(self.image.name))
def __str__(self):
return str(self.image)
class Meta:
verbose_name = 'Product Image'
verbose_name_plural = 'Product Images'
class StoreCategory(models.Model):
STORE_CATEGORIES= (
('GROCERY', ('Grocery')),
('MEATS', ('Meats')),
('FOODS & BEVERAGES', ('Foods')),
('COMPUTERS', ('Computers')),
('ELECTRONICS', ('Electronics')),
('HOME & OUTDOOR', ('Home & Outdoor')),
('FASHION & BEAUTY', ('Fashion & Beauty')),
('HEALTH', ('Health')),
('SPORTS & FITNESS', ('Sports & Fitness')),
('BABY', ('Baby')),
('BOOKS', ('Books')),
)
product = models.ForeignKey(Product,null=True, on_delete=models.CASCADE)
store_category = models.CharField(choices=STORE_CATEGORIES, default='GROCERY', max_length=30)
# objects = VariationManager()
class Meta:
verbose_name = 'Store Category'
verbose_name_plural = 'Store Categories'
def __str__(self):
# return str(self.product.name_of_product)
return '0 of category 1' .format(self.product.name_of_product, str(self.store_category))
python python-3.x database django
$endgroup$
add a comment |
$begingroup$
I am planning to develop a virtual shopping mall where stores of any kind can be registered, such as in a physical shopping mall. First I want to develop an efficient and effective database modeling for products and stores only. I wanted it be very flexible and user friendly. Here is the model design for Product
and Store
. How can I improve the database design?
My concern is mainly for the categories be user friendly. For example Men -> Clothing -> Shirts
as a category. If you wish, you can help me to improve the design as well, I would appreciate all recommendations.
I am using Python 3 and Django 1.11.
DAY = (( 'Sun', 'Sunday'),
( 'Mon', 'Monday'),
( 'Tue', 'Tuesday'),
( 'Wed', 'Wednesday'),
( 'Thu', 'Thursday'),
( 'Fri', 'Friday'),
( 'Sat', 'Saturday')
)
class OpeningHours(models.Model):
store = models.ForeignKey('Store', related_name="opening_hour")
weekday = models.CharField(choices=DAY, max_length=12)
opening_hour = models.TimeField()
closing_hour = models.TimeField()
class Meta:
verbose_name = 'Opening Hour'
verbose_name_plural = 'Opening Hours'
def ___str__(self):
return ' - '.format(self.weekday, str(self.opening_hour), str(self.closing_hour))
class Store(models.Model):
merchant = models.ForeignKey(User, blank=True, null=False)
token = models.CharField(default=token_generator, max_length=20, unique=True, editable=False)
name_of_legal_entity = models.CharField(max_length=250, blank=False, null=False)
pan_number = models.CharField(max_length=20, blank=False, null=False)
registered_office_address = models.CharField(max_length=200)
name_of_store = models.CharField(max_length=100)
email = models.EmailField(blank=False, null=False)
store_contact_number = models.PositiveIntegerField(blank=False, null=False)
# store_long = models.DecimalField(max_digits=12, decimal_places=8, null=True)
# store_lat = models.DecimalField(max_digits=12, decimal_places=8, null=True)
is_active = models.BooleanField(default=True)
class Meta:
verbose_name = 'Store'
def __str__(self):
return self.name_of_store
class Meta:
verbose_name = 'Store'
verbose_name_plural = 'Stores'
class Product(models.Model):
store = models.ForeignKey(Store)
token = models.CharField(default=token_generator, max_length=20, unique=True, editable=False)
category = models.ForeignKey('CatalogCategory', related_name='products')
brand = models.ForeignKey('Brand', related_name="product_brand")
image = models.ImageField(upload_to='products/images/')
name_of_product = models.CharField(max_length=120, blank=False,null=False)
description = models.TextField(blank=False,null=False)
price = models.DecimalField(decimal_places=2, max_digits=20)
discount = models.DecimalField(decimal_places=2, max_digits=20)
sales_price = models.DecimalField(decimal_places=2, max_digits=20)
is_active = models.BooleanField(default=True)
is_gurantee_available = models.BooleanField(default=False)
is_negotiated = models.BooleanField(default=False)
is_verified = models.BooleanField(default=False)
is_instock = models.BooleanField(default=False)
def __str__(self):
return self.name_of_product
class Meta:
verbose_name = 'Product'
verbose_name_plural = 'Products'
class Brand(models.Model):
name = models.CharField(max_length=100, blank=True, null=True)
logo = models.ImageField(upload_to='products/brand/images/')
class Meta:
verbose_name = 'Brand'
verbose_name_plural = 'Brands'
def __str__(self):
return self.name
class Variation(models.Model):
VAR_CATEGORIES = (
('size', 'size'),
('color', 'color'),
)
product = models.ForeignKey(Product)
token = models.CharField(default=token_generator, max_length=20, unique=True, editable=False)
category = models.CharField(max_length=10, choices=VAR_CATEGORIES)
title = models.CharField(max_length=50)
price = models.DecimalField(decimal_places=2, max_digits=20)
discount = models.DecimalField(blank=True ,null =True, decimal_places=2, max_digits=20)
active = models.BooleanField(default=True)
quantity = models.IntegerField(null=True , blank=True)
sales_price = models.DecimalField(blank=True ,null =True, decimal_places=2, max_digits=20)
image = models.ImageField(upload_to='products/images/')
class Meta:
verbose_name = 'Variation'
verbose_name_plural = 'Variations'
def __str__(self):
return '0 of 1 from 2' .format(self.product.name_of_product, self.title, self.product.store.name_of_store)
class CatalogCategory(models.Model):
token = models.CharField(default=token_generator, max_length=20, unique=True, editable=False)
parent = models.ForeignKey('self', blank=True, null=True, related_name='children')
name = models.CharField(max_length=300)
description = models.TextField(blank=True)
class Meta:
verbose_name = 'CatalogCategory'
verbose_name_plural = 'CatalogCategories'
def __str__(self):
return self.name
class ProductImage(models.Model):
product = models.ForeignKey(Product, null=True, blank=True, related_name="product_image")
image = models.ImageField(upload_to='products/images/')
updated = models.DateTimeField(auto_now_add=False, auto_now=True)
@property
def imageName(self):
return str(os.path.basename(self.image.name))
def __str__(self):
return str(self.image)
class Meta:
verbose_name = 'Product Image'
verbose_name_plural = 'Product Images'
class StoreCategory(models.Model):
STORE_CATEGORIES= (
('GROCERY', ('Grocery')),
('MEATS', ('Meats')),
('FOODS & BEVERAGES', ('Foods')),
('COMPUTERS', ('Computers')),
('ELECTRONICS', ('Electronics')),
('HOME & OUTDOOR', ('Home & Outdoor')),
('FASHION & BEAUTY', ('Fashion & Beauty')),
('HEALTH', ('Health')),
('SPORTS & FITNESS', ('Sports & Fitness')),
('BABY', ('Baby')),
('BOOKS', ('Books')),
)
product = models.ForeignKey(Product,null=True, on_delete=models.CASCADE)
store_category = models.CharField(choices=STORE_CATEGORIES, default='GROCERY', max_length=30)
# objects = VariationManager()
class Meta:
verbose_name = 'Store Category'
verbose_name_plural = 'Store Categories'
def __str__(self):
# return str(self.product.name_of_product)
return '0 of category 1' .format(self.product.name_of_product, str(self.store_category))
python python-3.x database django
$endgroup$
I am planning to develop a virtual shopping mall where stores of any kind can be registered, such as in a physical shopping mall. First I want to develop an efficient and effective database modeling for products and stores only. I wanted it be very flexible and user friendly. Here is the model design for Product
and Store
. How can I improve the database design?
My concern is mainly for the categories be user friendly. For example Men -> Clothing -> Shirts
as a category. If you wish, you can help me to improve the design as well, I would appreciate all recommendations.
I am using Python 3 and Django 1.11.
DAY = (( 'Sun', 'Sunday'),
( 'Mon', 'Monday'),
( 'Tue', 'Tuesday'),
( 'Wed', 'Wednesday'),
( 'Thu', 'Thursday'),
( 'Fri', 'Friday'),
( 'Sat', 'Saturday')
)
class OpeningHours(models.Model):
store = models.ForeignKey('Store', related_name="opening_hour")
weekday = models.CharField(choices=DAY, max_length=12)
opening_hour = models.TimeField()
closing_hour = models.TimeField()
class Meta:
verbose_name = 'Opening Hour'
verbose_name_plural = 'Opening Hours'
def ___str__(self):
return ' - '.format(self.weekday, str(self.opening_hour), str(self.closing_hour))
class Store(models.Model):
merchant = models.ForeignKey(User, blank=True, null=False)
token = models.CharField(default=token_generator, max_length=20, unique=True, editable=False)
name_of_legal_entity = models.CharField(max_length=250, blank=False, null=False)
pan_number = models.CharField(max_length=20, blank=False, null=False)
registered_office_address = models.CharField(max_length=200)
name_of_store = models.CharField(max_length=100)
email = models.EmailField(blank=False, null=False)
store_contact_number = models.PositiveIntegerField(blank=False, null=False)
# store_long = models.DecimalField(max_digits=12, decimal_places=8, null=True)
# store_lat = models.DecimalField(max_digits=12, decimal_places=8, null=True)
is_active = models.BooleanField(default=True)
class Meta:
verbose_name = 'Store'
def __str__(self):
return self.name_of_store
class Meta:
verbose_name = 'Store'
verbose_name_plural = 'Stores'
class Product(models.Model):
store = models.ForeignKey(Store)
token = models.CharField(default=token_generator, max_length=20, unique=True, editable=False)
category = models.ForeignKey('CatalogCategory', related_name='products')
brand = models.ForeignKey('Brand', related_name="product_brand")
image = models.ImageField(upload_to='products/images/')
name_of_product = models.CharField(max_length=120, blank=False,null=False)
description = models.TextField(blank=False,null=False)
price = models.DecimalField(decimal_places=2, max_digits=20)
discount = models.DecimalField(decimal_places=2, max_digits=20)
sales_price = models.DecimalField(decimal_places=2, max_digits=20)
is_active = models.BooleanField(default=True)
is_gurantee_available = models.BooleanField(default=False)
is_negotiated = models.BooleanField(default=False)
is_verified = models.BooleanField(default=False)
is_instock = models.BooleanField(default=False)
def __str__(self):
return self.name_of_product
class Meta:
verbose_name = 'Product'
verbose_name_plural = 'Products'
class Brand(models.Model):
name = models.CharField(max_length=100, blank=True, null=True)
logo = models.ImageField(upload_to='products/brand/images/')
class Meta:
verbose_name = 'Brand'
verbose_name_plural = 'Brands'
def __str__(self):
return self.name
class Variation(models.Model):
VAR_CATEGORIES = (
('size', 'size'),
('color', 'color'),
)
product = models.ForeignKey(Product)
token = models.CharField(default=token_generator, max_length=20, unique=True, editable=False)
category = models.CharField(max_length=10, choices=VAR_CATEGORIES)
title = models.CharField(max_length=50)
price = models.DecimalField(decimal_places=2, max_digits=20)
discount = models.DecimalField(blank=True ,null =True, decimal_places=2, max_digits=20)
active = models.BooleanField(default=True)
quantity = models.IntegerField(null=True , blank=True)
sales_price = models.DecimalField(blank=True ,null =True, decimal_places=2, max_digits=20)
image = models.ImageField(upload_to='products/images/')
class Meta:
verbose_name = 'Variation'
verbose_name_plural = 'Variations'
def __str__(self):
return '0 of 1 from 2' .format(self.product.name_of_product, self.title, self.product.store.name_of_store)
class CatalogCategory(models.Model):
token = models.CharField(default=token_generator, max_length=20, unique=True, editable=False)
parent = models.ForeignKey('self', blank=True, null=True, related_name='children')
name = models.CharField(max_length=300)
description = models.TextField(blank=True)
class Meta:
verbose_name = 'CatalogCategory'
verbose_name_plural = 'CatalogCategories'
def __str__(self):
return self.name
class ProductImage(models.Model):
product = models.ForeignKey(Product, null=True, blank=True, related_name="product_image")
image = models.ImageField(upload_to='products/images/')
updated = models.DateTimeField(auto_now_add=False, auto_now=True)
@property
def imageName(self):
return str(os.path.basename(self.image.name))
def __str__(self):
return str(self.image)
class Meta:
verbose_name = 'Product Image'
verbose_name_plural = 'Product Images'
class StoreCategory(models.Model):
STORE_CATEGORIES= (
('GROCERY', ('Grocery')),
('MEATS', ('Meats')),
('FOODS & BEVERAGES', ('Foods')),
('COMPUTERS', ('Computers')),
('ELECTRONICS', ('Electronics')),
('HOME & OUTDOOR', ('Home & Outdoor')),
('FASHION & BEAUTY', ('Fashion & Beauty')),
('HEALTH', ('Health')),
('SPORTS & FITNESS', ('Sports & Fitness')),
('BABY', ('Baby')),
('BOOKS', ('Books')),
)
product = models.ForeignKey(Product,null=True, on_delete=models.CASCADE)
store_category = models.CharField(choices=STORE_CATEGORIES, default='GROCERY', max_length=30)
# objects = VariationManager()
class Meta:
verbose_name = 'Store Category'
verbose_name_plural = 'Store Categories'
def __str__(self):
# return str(self.product.name_of_product)
return '0 of category 1' .format(self.product.name_of_product, str(self.store_category))
python python-3.x database django
python python-3.x database django
edited Aug 29 '17 at 5:05
Phrancis
14.8k649142
14.8k649142
asked Aug 29 '17 at 4:26
TushantTushant
1513
1513
add a comment |
add a comment |
1 Answer
1
active
oldest
votes
$begingroup$
The models look about right.
def imageName(self):
Well, ok, PEP-8 asks that you spell this image_name
, but,
whatever, I'm sure you had other constraints you were working within.
In STORE_CATEGORIES
I don't understand why Foods
is special.
It otherwise has DRY issues that could be addressed
by applying .upper()
or .title()
to a single copy of the list.
Looks good to me. Ship it!
$endgroup$
add a comment |
StackExchange.ifUsing("editor", function ()
return StackExchange.using("mathjaxEditing", function ()
StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
);
);
, "mathjax-editing");
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "196"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: false,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: null,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f174281%2fdatabase-modeling-for-products-and-store%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
$begingroup$
The models look about right.
def imageName(self):
Well, ok, PEP-8 asks that you spell this image_name
, but,
whatever, I'm sure you had other constraints you were working within.
In STORE_CATEGORIES
I don't understand why Foods
is special.
It otherwise has DRY issues that could be addressed
by applying .upper()
or .title()
to a single copy of the list.
Looks good to me. Ship it!
$endgroup$
add a comment |
$begingroup$
The models look about right.
def imageName(self):
Well, ok, PEP-8 asks that you spell this image_name
, but,
whatever, I'm sure you had other constraints you were working within.
In STORE_CATEGORIES
I don't understand why Foods
is special.
It otherwise has DRY issues that could be addressed
by applying .upper()
or .title()
to a single copy of the list.
Looks good to me. Ship it!
$endgroup$
add a comment |
$begingroup$
The models look about right.
def imageName(self):
Well, ok, PEP-8 asks that you spell this image_name
, but,
whatever, I'm sure you had other constraints you were working within.
In STORE_CATEGORIES
I don't understand why Foods
is special.
It otherwise has DRY issues that could be addressed
by applying .upper()
or .title()
to a single copy of the list.
Looks good to me. Ship it!
$endgroup$
The models look about right.
def imageName(self):
Well, ok, PEP-8 asks that you spell this image_name
, but,
whatever, I'm sure you had other constraints you were working within.
In STORE_CATEGORIES
I don't understand why Foods
is special.
It otherwise has DRY issues that could be addressed
by applying .upper()
or .title()
to a single copy of the list.
Looks good to me. Ship it!
answered 8 mins ago
J_HJ_H
4,592132
4,592132
add a comment |
add a comment |
Thanks for contributing an answer to Code Review Stack Exchange!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
Use MathJax to format equations. MathJax reference.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodereview.stackexchange.com%2fquestions%2f174281%2fdatabase-modeling-for-products-and-store%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
var $window = $(window),
onScroll = function(e)
var $elem = $('.new-login-left'),
docViewTop = $window.scrollTop(),
docViewBottom = docViewTop + $window.height(),
elemTop = $elem.offset().top,
elemBottom = elemTop + $elem.height();
if ((docViewTop elemBottom))
StackExchange.using('gps', function() StackExchange.gps.track('embedded_signup_form.view', location: 'question_page' ); );
$window.unbind('scroll', onScroll);
;
$window.on('scroll', onScroll);
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown