我已将ModelMultipleChoiceField
与
class PostForm(forms.ModelForm):
owner = forms.ModelChoiceField(queryset=User.objects.filter(is_staff=True, is_active=True))
groups = forms.ModelMultipleChoiceField(
queryset=Group.objects.all(),
required=False,
widget=forms.CheckboxSelectMultiple())
categories = forms.ModelMultipleChoiceField(
queryset=Category.objects.filter(is_root=True),
required=False,
widget=forms.CheckboxSelectMultiple())
class Meta:
model = Post
fields = ('name', 'title', 'url', 'image', 'desc', 'content', 'start', 'pinHome', 'pinNation', 'pinSchool', 'owner', 'poster', 'groups', 'categories')
和我的分类模型有
class Category(models.Model):
parents = models.ManyToManyField("self", blank=True, related_name='childs', symmetrical=False)
我的模板
{% for category in form.categories %}
<label>
{{category}}
{% for childs in category.childs.all %}
{{childs}}
{% endfor %}
</label>
{% endfor %}
我如何访问&#34;孩子&#34;模板上的类别。我尝试了{{category.childs.all}}
但它没有用。