I’d like to override ModelChoiceField template. I have a category model with attributes such as name and depth – categories are nested, and depth tells me how deep into the tree given category is. What I’m trying to do is to indent category name by depth, so if I had two categories – depths 2 and 4, then I’d like to indent their names by 2 and 4 spaces in the select box. How can I do it?
I’d like to override ModelChoiceField template. I have a category model with attributes such
Share
have you considered django mptt?
it adds a whole bunch of helpers for dealing with tree data, including nice nested widgets
otherwise, i think i’ve used something like this in the past
(copied form old codebase, so may need tweaking to work. also, think it was written for django 1.2 so probably needs updating)