[Answered ]-Only allow leaf category as a choice – Django

2👍

Category.objects.filter(children__isnull=True)


class MyModelForm(forms.ModelForm):
    def __init__(self, *args, **kwargs):
        super(MyModelForm, self).__init__(*args, **kwargs)
        self.fields['myfield'].queryset = Category.objects.filter(children__isnull=True)

Leave a comment