database - Product Model with type and subtypes Django 1.10 -


hi all!! need create product model wich have multiples types , type have multiples subtypes

i share models code , please tell me if i'm going in way.

class productcatalog(models.model):     name= models.charfield(max_length=100, null=false, blank=false)      def __str__(self):         return self.name      def get_absolute_url(self):         return reverse("product_detail", kwargs={"id": self.id})   class producttype(models.model):     productid = models.foreignkey(productcatalog)     typename = models.charfield(max_length=200)  class product_subtype(models.model):     typeid = models.foreignkey(producttype)     subtype_name = models.charfield(max_length=200, null=false, blank=false) 

this final result want get:

product name

  • type 1:
    • sub type 1
    • sub type 2
    • sub type 3
  • type 2:
    • sub type 1
    • sub type 2

etc.

in example, productcatalog may have multiple producttype, , producttype may have multiple product_subtype.

this common way approach many-to-one association in django models.


Comments