I am trying to use TreeBeard's built in Form's with django forms (not admin). I specifically wanted to replace the rendering of a Select ForeignKey field with TreeBeard forms format. I thought I could do this by declaring the field in my ModelForm, but I've had no success. I'm new to django so my understanding is limited.
These are my initial classes in my forms.py
MyCategories = movenodeform_factory(Category)
class CreatePost(ModelForm):
class Meta:
model = Post
fields = ['title', 'category', 'region', 'content', ]
I tried implementing it by declaring the category field in the beginning but this clearly isn't the way to do it. The declaration does return an html formatted category list, but I can't replace the Post category (which is a ForeignKey)with it.
class CreatePost(ModelForm):
category = movenodeform_factory(Category)
class Meta:
model = Post
fields = ['title', 'category', 'region', 'content', ]
The reason I want to use TreeBeard forms is because of the way it nests the fields according to the category hierarchy.
SOLVED: This ended up being much simpler than I realized.
class CreatePost(ModelForm):
CHOICES = MoveNodeForm.mk_dropdown_tree(Category)
category = ChoiceField(choices=CHOICES)
class Meta:
model = Post
fields = ['title', 'category', 'region', 'content', ]