On Tue, 2009-02-10 at 15:37 -0800, Adam Nelson wrote: > I'm looking at the documentation here: > > http://docs.djangoproject.com/en/dev/ref/templates/builtins/#regroup > > And am looking for the best practices way to deal with doing that from > within the manager.
You point to documentation for a template tag and then talk about "the manager". I don't understand what you're asking here. Is it how to create a data structure appropriate for passing to regroup (which would more likely be a view function or, possibly, a model method)? Or something else? > This seems like a common issue: > > 1. I have two models, one foreign keys to the other (comments -> > bookmarks) > 2. I want, for each bookmark, to list each comment_description. > > This would be the dictionary (or I could use a queryset, or a list, or > ideally a dictionary of lists, or whatever is considered best > practice) > > [{'comment_id': 1, 'bookmark_id': 1, 'comment_description': > u'Bookmark1 Description'}, {'comment_id': 2, 'bookmark_id': 1, > 'comment_description': u'Bookmark1 Another Description'}, {'id': 3, > 'comment_id': 2, 'comment_description': u'Bookmark2 Description'}] > > I want: > > bookmark_id 1, comment_descriptions "Bookmark1 Description","Bookmark1 > Another Description" > bookmark_id 2, comment_descriptions "Bookmark2 Description" It sounds like you're wanting to group everything for the same bookmark_id together. So the regroup tag is the right thing. Assuming "dataset" is your list of dictionaries: {% regroup dataset by bookmark_id as ordered_dataset %} {% for entry in ordered_dataset %} {{ entry.grouper }} <ul>{% for data in entry.list %} <li>{{ data.comment_description }}</li> {% endfor %}</ul> {% endfor %} I've added a little bit of HTML formatting just to make things clear, but, at this point, it's basically the same as the example in the documentation for the regroup tag. > > The Python docs are really tough to navigate Huh?! The Python docs are generally widely considered to be excellently structured. There's both a list of all available modules and a general index. What, exactly are you looking for that is hard to find? > and while the Django docs > are excellent, I can't find the standard solution for this. Again, depends on what you're actually wanting to do. Likely answer is that there are 14 different solutions, all equally good. Not something that's going to be covered in the Django documentation, since it's just going to be normal Python programming and that is amply covered elsewhere. Regards, Malcolm --~--~---------~--~----~------------~-------~--~----~ 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 -~----------~----~----~----~------~----~------~--~---