diff options
author | Parabola <dev@list.parabolagnulinux.org> | 2011-05-21 05:41:26 +0000 |
---|---|---|
committer | Parabola <dev@list.parabolagnulinux.org> | 2011-05-21 05:41:26 +0000 |
commit | 62059d83aea71ac7bde8902b20221e52c86a810b (patch) | |
tree | 758bd028d43a30893ba6261f39b1ebdbebbbf6e3 /todolists/utils.py | |
parent | 081223981aa520f792757a1776588756a4107fd4 (diff) | |
parent | fd9ecb6eb1c8ee56adfbb58640d7a98baa6cd62c (diff) |
Merge branch 'master' of /srv/git/projects/parabolaweb
Diffstat (limited to 'todolists/utils.py')
-rw-r--r-- | todolists/utils.py | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/todolists/utils.py b/todolists/utils.py new file mode 100644 index 00000000..894f3f1d --- /dev/null +++ b/todolists/utils.py @@ -0,0 +1,19 @@ +from django.db.models import Count + +from main.models import Todolist + +def get_annotated_todolists(): + qs = Todolist.objects.all() + lists = qs.select_related('creator').annotate( + pkg_count=Count('todolistpkg')).order_by('-date_added') + incomplete = qs.filter(todolistpkg__complete=False).annotate( + Count('todolistpkg')).values_list('id', 'todolistpkg__count') + + # tag each list with an incomplete package count + lookup = dict(incomplete) + for todolist in lists: + todolist.incomplete_count = lookup.get(todolist.id, 0) + + return lists + +# vim: set ts=4 sw=4 et: |