我需要根据已显示的类别类型显示子类别。像这样的东西
Group 1
==>Group1_subcat1
==>Group1_subcat2
Group 2
==>Group2_subcat1
==>Group2_subcat2
楷模
class Category(models.Model):
category=models.CharField(max_length=20)
description=models.CharField(max_length=64)
group=models.ForeignKey(Group)
形式
class ContactForm(forms.Form):
'''Creates a form for the application to add a contact. '''
firstname = forms.CharField(max_length=20)
lastname = forms.CharField(max_length=20)
email = forms.EmailField()
group = forms.ModelChoiceField(queryset=Group.objects.all())
category=forms.ModelChoiceField(queryset=Category.objects.filter(group=group.id))//error is here
html
{% csrf_token %}
{{ form.as_p }}
{% endfor %}