class Category(models.Model):
slug = models.SlugField()
parent = models.ForeignKey('self', blank=True, null=True)
- Категория
— Подкатегория
Иерархия 2х уровневая
Или куда копнуть…
Спасибо!
class Category(models.Model):
slug = models.SlugField()
parent = models.ForeignKey('self', blank=True, null=True)
root_categories = Category.objects.filter(parent=None)
{% for root_category in root_categories %}
- {{root_category}}
{% for sub_category in root_category.category_set.all %}
--- {{sub_category}}
{% endfor %}
{% endfor %}
DaevaornСпасибо большое )))root_categories = Category.objects.filter(parent=None){% for root_category in root_categories %}
- {{root_category}}
{% for sub_category in root_category.category_set.all %}
--- {{sub_category}}
{% endfor %}
{% endfor %}