In my Django App I have the following model:
class SuperCategory(models.Model):
name = models.CharField(max_length=100,)
slug = models.SlugField(unique=True,)
class Category(models.Model):
name = models.CharField(max_length=100,)
slug = models.SlugField(unique=True,)
super_category = models.ForeignKey(SuperCategory)
What I'm trying to accomplish in Django's Admin Interface is the rendering of Category using widget CheckboxSelectMultiple but with Category somehow grouped by SuperCategory, like this:
Category:
Sports: <- Item of SuperCategory
[ ] Soccer <- Item of Category
[ ] Baseball <- Item of Category
[ ] ...Politics: <- Another item of SuperCategory
[ ] Latin America
[ ] North america
[ ] ...
Does anybody have a nice suggestion on how to do this?
Many thanks.
After some struggle, here is what I got.
First, make ModelAdmin call a ModelForm:
Then, in the form, use use a custom widget to render:
Finally, the widget:
Not the most elegant solution, but hey, it worked.