Sorting the output of regroup
I have a small cms. I have two models, one for Mainmenu items, and one
for page with content with a foreignkey to the main menu items:
class Mainmenu_items(models.Model):
title = models.CharField(max_length=60)
mainmenu_order = models.IntegerField(default='99')
class Page(models.Model):
title = models.CharField(max_length=60)
text = models.TextField(blank=True)
menu = models.ForeignKey(Mainmenu, null=True, blank=True)
menu_order = models.IntegerField(default='99')
In the view:
menu_items = Page.objects.select_related()
In de template I have:
{% regroup menu_items by menu.titel as menu_list %}
<ul class="mainmenu">
{% for menu in menu_list %}
<li>
<a href="/{{menu.list.0.menu.slug}}" >
<span>{{ menu.grouper }}</span></a>
<ul>
{% for item in menu.list %}
<li><a href="/{{ item.slug }}"><span> {{ item.menu_titel }}</
span></a></li>
{% endfor %}
</ul>
</li>
{% endfor %}
</ul>
This renders a menu correctly:
Mainmenu2
-page1
-page2
-page3
Mainmenu1
-links
-content
I want however control the order of appearance of the mainmenu items,
and the pages (using the mainmenu_order and the menu_order from the
model)
When I use dictsort in the template, or order_by in the view things go
wrong. When page1 and page2+3 have different menu_order values the
menu is rendered like this:
Mainmenu2
-page1
Mainmenu2
-page2
-page3
Mainmenu1
etc..
Mainmenu2 appears also twice.
Any idea what is the best way to accomplish this?
Rob
--
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+unsubscribe@googlegroups.com.
For more options, visit this group at http://groups.google.com/group/django-users?hl=en.

0 Comments:
Post a Comment
Subscribe to Post Comments [Atom]
<< Home