我尝试使用 django smart select 链接四个类别,但它无法正常工作。Django 不会从最后一个中获取或输入值。服装尺寸。它工作正常,直到衣服尺寸。该选择框始终为空。我的模型:
这里可能是什么问题?这似乎不是 js 问题,因为其他字段工作正常。
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)