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










6












$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))









share|improve this question











$endgroup$
















    6












    $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))









    share|improve this question











    $endgroup$














      6












      6








      6


      1



      $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))









      share|improve this question











      $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






      share|improve this question















      share|improve this question













      share|improve this question




      share|improve this question








      edited Aug 29 '17 at 5:05









      Phrancis

      14.8k649142




      14.8k649142










      asked Aug 29 '17 at 4:26









      TushantTushant

      1513




      1513




















          1 Answer
          1






          active

          oldest

          votes


















          0












          $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!





          share









          $endgroup$













            Your Answer





            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
            );



            );













            draft saved

            draft discarded


















            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









            0












            $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!





            share









            $endgroup$

















              0












              $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!





              share









              $endgroup$















                0












                0








                0





                $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!





                share









                $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!






                share











                share


                share










                answered 8 mins ago









                J_HJ_H

                4,592132




                4,592132



























                    draft saved

                    draft discarded
















































                    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.




                    draft saved


                    draft discarded














                    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





















































                    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







                    Popular posts from this blog

                    名間水力發電廠 目录 沿革 設施 鄰近設施 註釋 外部連結 导航菜单23°50′10″N 120°42′41″E / 23.83611°N 120.71139°E / 23.83611; 120.7113923°50′10″N 120°42′41″E / 23.83611°N 120.71139°E / 23.83611; 120.71139計畫概要原始内容臺灣第一座BOT 模式開發的水力發電廠-名間水力電廠名間水力發電廠 水利署首件BOT案原始内容《小檔案》名間電廠 首座BOT水力發電廠原始内容名間電廠BOT - 經濟部水利署中區水資源局

                    Prove that NP is closed under karp reduction?Space(n) not closed under Karp reductions - what about NTime(n)?Class P is closed under rotation?Prove or disprove that $NL$ is closed under polynomial many-one reductions$mathbfNC_2$ is closed under log-space reductionOn Karp reductionwhen can I know if a class (complexity) is closed under reduction (cook/karp)Check if class $PSPACE$ is closed under polyonomially space reductionIs NPSPACE also closed under polynomial-time reduction and under log-space reduction?Prove PSPACE is closed under complement?Prove PSPACE is closed under union?

                    Is my guitar’s action too high? Announcing the arrival of Valued Associate #679: Cesar Manara Planned maintenance scheduled April 23, 2019 at 23:30 UTC (7:30pm US/Eastern)Strings too stiff on a recently purchased acoustic guitar | Cort AD880CEIs the action of my guitar really high?Μy little finger is too weak to play guitarWith guitar, how long should I give my fingers to strengthen / callous?When playing a fret the guitar sounds mutedPlaying (Barre) chords up the guitar neckI think my guitar strings are wound too tight and I can't play barre chordsF barre chord on an SG guitarHow to find to the right strings of a barre chord by feel?High action on higher fret on my steel acoustic guitar