0

I've used Django.treebeard to create a hierarchical system to classify books like so:

enter image description here

The 'genres' model is related to another model by a many-to-many relationship, and I need to be able to select the right genres (ie, Fiction>Adult>Science Fiction>Hard Science Fiction) in the admin page for the other model. Checkboxes seem to be the best way to do this, but when I use them in they look like this:

enter image description here

So I can't see the different levels of the hierarchy. The best I've been able to come up with is adding the following to the Models:

    def __str__(self):
    return '%s%s' % ('--' * self.depth, self.name)

Which results in this, which is not much better:

enter image description here

What I need is for the checkboxes themselves to move, not just the text, and to have functionality like being able to 'open' and 'shut' the parent categories, select/deselect all children by selecting the parent etc. Is there any way to do this?

  • Why don't you just create an Admin action as described here https://docs.djangoproject.com/en/4.0/ref/contrib/admin/actions/ ? Then you can just reuse the functionality already provided. – jrief Jul 01 '22 at 23:15
  • @jrief - which part of the linked article should I be looking at? Also what functionality are you referring to? – Gareth Watkins-Fremont Jul 01 '22 at 23:48
  • By writing your own action function and adding it to your Model Admin. – jrief Jul 02 '22 at 10:46

0 Answers0