我有这个:
在模型.py
class Category(models.Model):
Name = models.CharField(max_length=50)
Description = models.CharField(max_length=150)
def __unicode__(self):
return self.Description
class Subcategory(models.Model):
Category = models.ForeignKey(Category)
Name = models.CharField(max_length=50)
Description = models.CharField(max_length=150)
def __unicode__(self):
return self.Description
class Smartgrid(models.Model):
Category = models.ForeignKey(Category)
Subcategory = models.ForeignKey(Subcategory)
Descriptor = models.CharField(max_length=150)
def __unicode__(self):
return self.Descriptor
在 forms.py 中:
class SmartgridForm(forms.ModelForm):
class Meta:
model = Smartgrid
在views.py
def new_point(request):
if request.method=='POST':
form = SmartgridForm(request.POST, request.FILES)
if form.is_valid():
form.save()
return HttpResponseRedirect('/gis')
else:
form = SmartgridForm()
return render_to_response('SmartgridForm.html', {'form':form}, context_instance=RequestContext(request))
问题:
我希望用户在 SmartgridForm.html 中选择类别后,子类别字段仅显示这些子类别,其中类别 = 已选择类别
谢谢 !!!!
JDC。