I have the following models:
class Category(models.Model):
name = models.CharField(max_length=200)
slug = models.SlugField()
parent = models.ForeignKey('self', blank = True, null = True, related_name="children")
class Business(models.Model):
user = models.OneToOneField(User)
name = models.CharField(max_length=200)
slug = models.SlugField()
category = models.ForeignKey(Category)
city = models.ForeignKey(City)
When adding a business using a modelForm, non-leaf categories show up in the select box.
For example, assuming that we have the following category hierarchy:
- Cars
-- Car Rental
-- Car Dealership
-- Mechanics
- Restaurants
-- Burgers
-- Chinese
-- Sushi
-- Pizza
-- Latin american
-- Mexican
-- Venezuelan
-- Argentinian
With this hierarchy, all the choices but Cars, Restaurants and Latin American should show up in the Category select box, since these have children categories.
1 Answer