Thank you for your input, Malcolm. I've made up something based on your suggestions in revision 56: http://codebrowse.launchpad.net/~mikl/kaplan/kaplan.dev/revision/56
Sorry for missing your last name in the commit message, but I was off- line when I committed this (7 hour train journey, what would I do without decentralised VCS.) Kind regards, Mikkel Høgh On Oct 19, 12:21 pm, Malcolm Tredinnick <[EMAIL PROTECTED]> wrote: > On Thu, 2007-10-18 at 15:25 -0700, Mikkel Høgh wrote: > > I have a bit of a problem - I'm creating a GTD-focused task management > > app for Django, mainly for my own benefit, but it's open source if any > > one cares. > > > I've been trying to implement a taxonomy system like the one Drupal > > uses. Only problem is that I find it difficult to get the right data > > out into the template system. > > > As an example, I have a list of Task objects, which is supposed to be > > displayed to the user. These Task objects all have Term object > > associated with them (ManyToMany). The Term objects belong > > (ForeignKey) to a Vocabulary object. I want to get the Term objects by > > their Vocabulary so I can display them in different columns. > > > Lets say I have a Task object called 'Fix the apache configuration on > > xyz server', which has the Term objects 'Urgent' (from the Priority > > Vocabulary) and 'Work' (from the Context Vocabulary). > > > Currently, I have a bit of a kludge where I've put a refresh method on > > the Task object that generates a dictionary with vocabulary names as > > keys and as value a string containing a comma-separated list of all > > the terms from that Vocabulary associated with the Term object in > > question. > > > I would like to be able to access the Term objects directly in the > > template, so I could get the absolute URL for them in the "right" way > > or if that's not feasible, some other solution, because I need the > > aforementioned string to have links to the Term objects in question... > > It's not completely clear to me what you want to do here. Is this what > you are trying to accomplish: given a Task object, find all the > associated Term objects and group them by their vocabulary attribute? > > If that's the case, then I think your current code is fairly close. > However, instead of storing term.title in the dictionary, just store the > term object itself and don't both joining the items together at the end. > This way, after calling refresh(), you can do something like this in > your template: > > {% for elt in task.t.items %} > Vocabulary word is {{ elt.0 }} > Associated terms are: > {% for term in elt.1 %} > {{ term.title }} > {% endfor %} > {% endfor %} > > (or anything more advanced). If you're using post-0.96 Django, you can > even write > > {% for vocab, term in task.t.items %} > > but that's mostly a matter of taste. The functionality is the same. > > If you want to do this without the refresh() method, I suspect you're > probably out of luck. the hard part is the grouping based on the > vocabulary term -- you can't do that simply as a queryset. If it was me, > though, I wouldn't make refresh() adjust the task object. I would have > it return the dictionary, so you can do all of the above stuff as > > {% for vocab, term in task.get_vocab_and_terms %} > > without having to remember to call task.refresh() in your view. > > 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 [EMAIL PROTECTED] For more options, visit this group at http://groups.google.com/group/django-users?hl=en -~----------~----~----~----~------~----~------~--~---