I try to chain four categories with django smart select but it does not work properly. Django does not take or input values from in the last one. clothing_size. It is working properly till clothing sizes. That selectbox is always empty. My model:
What could be the problem here? That does not seem like js problem, because other fields are working properly.
from django.db import models
from smart_selects.db_fields import ChainedForeignKey
# Create your models here.
class MainCategory(models.Model):
name = models.CharField(max_length=20, null=True)
def __str__(self):
return self.name
class ClothingType(models.Model):
main_category = models.ForeignKey(MainCategory, on_delete=models.CASCADE, null=True)
clothing_type = models.CharField(max_length=64, null=True)
def __str__(self):
template = '{0.main_category} {0.clothing_type}'
return template.format(self)
class ClothingSubType(models.Model):
main_category = models.ForeignKey(MainCategory, on_delete=models.CASCADE, null=True)
# clothing_type = models.ForeignKey(ClothingType, on_delete=models.CASCADE, null=True)
clothing_type = ChainedForeignKey(ClothingType, chained_field="main_category", chained_model_field="main_category", show_all=False, auto_choose=True, sort=True, null=True)
clothing_sub_type = models.CharField(max_length=254, null=True)
def __str__(self):
template = '{0.main_category} {0.clothing_type} {0.clothing_sub_type}'
return template.format(self)
class ClothingSize(models.Model):
main_category = models.ForeignKey(MainCategory, on_delete=models.CASCADE, null=True)
clothing_type = ChainedForeignKey(ClothingType, chained_field="main_category", chained_model_field="main_category", show_all=False, auto_choose=True, sort=True, null=True)
clothing_sub_type = ChainedForeignKey(ClothingSubType, chained_field="clothing_type", chained_model_field="clothing_type", show_all=False, auto_choose=True, sort=True, null=True)
# clothing_sub_type = models.ForeignKey(ClothingSubType, on_delete=models.CASCADE, null=True)
clothing_size = models.CharField(max_length=30, null=True)
def __str__(self):
template = '{0.main_category} {0.clothing_type} {0.clothing_sub_type} {0.clothing_size}'
return template.format(self)
class Product(models.Model):
name = models.CharField(max_length=30, null=True)
sku = models.CharField(max_length=20, null=True)
main_category = models.ForeignKey(MainCategory, on_delete=models.CASCADE, null=True)
clothing_type = ChainedForeignKey(
ClothingType,
chained_field="main_category",
chained_model_field="main_category",
show_all=False,
auto_choose=True,
sort=True,
null=True
)
product_category = ChainedForeignKey(
ClothingSubType,
chained_field="clothing_type",
chained_model_field="clothing_type",
show_all=False,
auto_choose=True,
sort=True,
null=True
)
clothing_size = ChainedForeignKey(
ClothingSize,
chained_field="clothing_sub_type",
chained_model_field="clothing_sub_type",
show_all=False,
auto_choose=True,
sort=True,
null=True
)
def __str__(self):
template = '{0.name}'
return template.format(self)