Sample structure:
ALL UPPERCASE: Category
Mixed Case: Item
ROOT
├── BOOKS
│ ├── FICTION
│ │ └── CLASSICS
│ └── NON-FICTION
├── CLOTHING
└── ELECTRONICS
├── LAPTOPS
├── PHONES
│ ├── APPLE
│ │ ├── iPhone 6
│ │ ├── iPhone 6 Plus
│ │ ├── iPhone 6S
│ │ └── iPhone 6S Plus
│ ├── MOTOROLA
│ │ ├── Moto G4
│ │ ├── Moto G4 Play
│ │ ├── Moto G4 Plus
│ │ └── Moto X
│ └── SAMSUNG
└── TABLETS
└── APPLE
I'm trying to have my index page only show the "ELECTRONICS" category. The "CLOTHING" category shouldn't show up since it's empty and the "BOOKS" category shouldn't show up either since, although it has child categories, the child categories don't have any items.
Similarly, the "ELECTRONICS" page should only show the "PHONES" category. The "LAPTOPS" category shouldn't show up since it's empty and the "TABLETS" category shouldn't show up either since, although it has a child category, that child category doesn't have any items.
Similarly, the "PHONES" page should only show the "APPLE" and "MOTOROLA" categories since the "SAMSUNG" category is empty.
What I've tried for the index page:
Category.objects.root_nodes().exclude(children__isnull=True)
This successfully excludes the "CLOTHING" category, but it does not exclude the "BOOKS" category. I understand why this doesn't work, but I don't know what to do instead.