Lets say I have a bunch of categories which can optionally contain subcategories... What would be the ideal way to go about a) preparing this data for my templates, and b) displaying this data in m templates
Here is what I currently have.. it feels dirty --------------------------------------------------------------------------- def article_browser(request, c): categories = Category.objects.filter(parent__isnull=True).order_by ('title') for category in categories: category.children = category.category_set.all().order_by('title') c = RequestContext(request,{ 'categories': categories, }) ------------------------------------------------------------ then in my template --------------------------------------------------------------------------------------------------------- {% for category in categories %} <div class="category"> <a class=drop href="javascript: toggle_subcategories ({{ category.id }}, true);" id="dropbutton{{ category.id }}"><div class="arrow collapsed" id="arrow{{ category.id }}"></div></a> <div class="title titlesmall"><a href="/browse/{{ category.slug }}/"> {{ category.title }}</a></div> <div class=clear></div> </div> {% if category.children %} <div class="subcategories" id="subcategories{{ category.id }}"> {% for category in category.children %} <div class="category"><a href="/browse/{{ category.slug }}/"> {{ category.title }}</a></div> {% endfor %} </div> {% endif %} {% endfor %} ------------------------------------------------------------------------------------------ --~--~---------~--~----~------------~-------~--~----~ You received this message because you are subscribed to the Google Groups "Django users" group. To post to this group, send email to django-users@googlegroups.com To unsubscribe from this group, send email to django-users+unsubscr...@googlegroups.com For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---