diff options
author | Nicolás Reynolds <fauno@kiwwwi.com.ar> | 2011-05-21 02:11:13 -0300 |
---|---|---|
committer | Nicolás Reynolds <fauno@kiwwwi.com.ar> | 2011-05-21 02:11:13 -0300 |
commit | a30350ac6e76c66d14f6d78ed2b5ae4e5799c79c (patch) | |
tree | a2b7127366a1b9d8d5be9fcda5abefacef7d2579 /todolists/utils.py | |
parent | d8f82d9d72eec6042536797f75e06a9296f4cc71 (diff) | |
parent | 2470c543d60c96343a5b0fefe04464b5b445b859 (diff) |
Merge branch 'master' of git://projects.archlinux.org/archweb
Conflicts:
devel/views.py
feeds.py
templates/devel/index.html
templates/packages/flag.html
templates/public/index.html
todolists/views.py
urls.py
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: |