class Make(models.Model):
name = models.CharField(max_length = 50)
#category = models.ManyToManyField(Category)
def __unicode__(self):
return self.name
class Category(models.Model):
make = models.ManyToManyField(Make)
name = models.CharField(max_length = 40)
def __unicode__(self):
return self.name
class Subcategory(models.Model):
name = models.CharField(max_length = 40)
category = models.ForeignKey(Category)
def __unicode__(self):
return self.name
makes = Make.objects.all()
MAKE_CHOICES = [(str(cat.name),str(cat.name)) for cat in makes]
categories = Category.objects.all()
CAT_CHOICES = [(str(cat.name),str(cat.name)) for cat in categories]
subcategories = Subcategory.objects.all()
SUB_CHOICES = [(str(cat.name),str(cat.name)) for cat in subcategories]
class Subscription(models.Model):
make = models.CharField(max_length = 40,choices = MAKE_CHOICES)
#category = models.ManyToManyField(Category)
category = models.CharField(max_length = 40,choices = CAT_CHOICES)
subcategory = models.CharField(max_length = 40,choices = SUB_CHOICES)
#subcategory = models.ManyToManyField(Subcategory)
fixer = models.ForeignKey(Fixer)
subscribed_on = models.DateTimeField()
expires_on = models.DateTimeField()
user = models.ForeignKey(User)
当显示或提示订阅字段时,我需要它们动态生成, 如果选择了一个类别,那么子类别字段应该只显示与该特定字段相关的所有子类别。