I’ve got a model MyModel with a category field. The Category model has a ForeignKey to itself.
In the admin of MyModel I’d like to have the following:
1- a select box with the category instances having no parent, with the possibility to add one (the usual ‘+’ button for a ForeignKey)
2- if the selected category has children, show another select box with the children, and the ‘+’ button
3->2
Note: the number of subcategories is not fixed.
Is there any package that can do that? I can do it myself with some ajax, but it seems to be a common task, and I’d like to be sure there is no package to manage this easily.
Thanks
class Category(models.Model):
parent = models.ForeignKey('self', related_name="children")
name = models.CharField(max_length=100)
class MyModel(models.Model):
name = models.CharField(max_length=100)
category = models.ForeignKey(Category)
There is django-categories package, which add a select box with all category like:
https://github.com/callowayproject/django-categories