[Answered ]-Django self-referential model as a many-to-many inline tree in the admin site

2👍

If you register the Item model with mptt. You can overwrite the unicode method:

class Item(models.Model):

    ...  

    def __unicode__(self):
         return '%s%s' % ('  ' * self.level, super(MarkerCategory, self).__unicode__())

If you want a cleaner solution, you should overwrite the form, and change the widget and to do this logic in this specific widget.

👤Goin

0👍

I hate when browsers are “smart”.

from django.utils.safestring import mark_safe

...

class Item(models.Model):

    ...  

    def __unicode__(self):
         return mark_safe('%s%s' % (' ' * 4 * self.level,
                          super(Item, self).__unicode__()))

But I recomend that this logic is in a specify widget

👤Goin

Leave a comment