A django-mptt TreeNodeChoiceField
gives indented select options, whereas I can filter my results using django-autocomplete-light. However, the ModelSelect2
widget overwrites the rendered html, which removes the indentation.
I would like to combine the two. Any idea how I could achieve this?
models.py:
class Foo(MPTTModel):
name = models.CharField(max_length=50)
parent = TreeForeignKey('self', null=True, blank=True, related_name='children', db_index=True)
class MPTTMeta:
order_insertion_by = ['name']
forms.py:
class FooForm(forms.ModelForm):
parent = TreeNodeChoiceField(queryset=Foo.objects.all(), widget=autocomplete.ModelSelect2(url='foo-autocomplete'))
class Meta:
model = Foo
fields = ('name', 'parent', )