My requirement is: create category and product table according to the store selected.
class Category(models.Model):
parent = models.ForeignKey("Category", blank=True, null=True,
related_name="children", verbose_name=_("Parent Category"))
name = models.CharField(verbose_name=_("Name"), max_length=255)
path = models.CharField(verbose_name=_("Path"), max_length=200)
description = models.TextField(verbose_name=_("Description"))
class CategoryStore(model.Model):
default = models.ForeignKey("Category", related_name="store_category",
verbose_name=_("Default Value"))
parent = models.ForeignKey("CategoryStore", blank=True, null=True,
related_name="children", verbose_name=_("Parent Category"))
name = models.CharField(verbose_name=_("Name"), max_length=255)
description = models.TextField(verbose_name=_("Description"))
store = models.ForeignKey("Store", related_name="store_category",
verbose_name=_("Store"))
CategoryStore model will have table names as category_store_1, category_store_2, etc. Would like to create the tables on the fly after a store is created. If, we add another field to the model, should have option to add to all the tables the new field.
class Product(models.Model):
name = models.CharField(verbose_name=_("Name"), max_length=255)
description = models.TextField(verbose_name=_("Description"))
class ProductStore(model.Model):
default = models.ForeignKey("Product", related_name="store_product",
verbose_name=_("Default Value"))
name = models.CharField(verbose_name=_("Name"), max_length=255)
description = models.TextField(verbose_name=_("Description"))
store = models.ForeignKey("Store", related_name="store_product",
verbose_name=_("Store"))
This also has same requirement as the category. One addition is that, option to create new field to both the model, new field on the fly from admin form. It will be attributes for the product. Instead of another table to store attribute values, want to add a new field to the Product and ProductStore model on the fly.