Skip to content

Instantly share code, notes, and snippets.

@gvangool
Created November 19, 2012 13:10
Show Gist options
  • Save gvangool/4110553 to your computer and use it in GitHub Desktop.
Save gvangool/4110553 to your computer and use it in GitHub Desktop.
Cavallo test
>>> from cavallo.course.models import Course
>>> from django.db.models import Count
>>> from cavallo.event.models import Event
>>> event = Event.objects.all()[0]
>>> event
<Event: Manege Bosscherhof - Indoor Jumping>
>>> Course.objects.filter(event=event).annotate(count_combinations=Count('combination'))
[<Course: Clearround pony's en paarden 60 cm (Manege Bosscherhof - Indoor Jumping)>, <Course: Clearround pony's en paarden 80 cm (Manege Bosscherhof - Indoor Jumping)>, <Course: Pony's 80 cm (Manege Bosscherhof - Indoor Jumping)>, <Course: Pony's 90 cm (Manege Bosscherhof - Indoor Jumping)>, <Course: Pony's 100 cm (Manege Bosscherhof - Indoor Jumping)>, <Course: Reeks A 90 cm (Manege Bosscherhof - Indoor Jumping)>, <Course: Reeks B 100 cm (Manege Bosscherhof - Indoor Jumping)>, <Course: Serie 1 110 cm (Manege Bosscherhof - Indoor Jumping)>, <Course: Top Score 100 cm (Manege Bosscherhof - Indoor Jumping)>]
>>> Course.objects.filter(event=event).annotate(count_combinations=Count('combination__deleted'))
[<Course: Clearround pony's en paarden 60 cm (Manege Bosscherhof - Indoor Jumping)>, <Course: Clearround pony's en paarden 80 cm (Manege Bosscherhof - Indoor Jumping)>, <Course: Pony's 80 cm (Manege Bosscherhof - Indoor Jumping)>, <Course: Pony's 90 cm (Manege Bosscherhof - Indoor Jumping)>, <Course: Pony's 100 cm (Manege Bosscherhof - Indoor Jumping)>, <Course: Reeks A 90 cm (Manege Bosscherhof - Indoor Jumping)>, <Course: Reeks B 100 cm (Manege Bosscherhof - Indoor Jumping)>, <Course: Serie 1 110 cm (Manege Bosscherhof - Indoor Jumping)>, <Course: Top Score 100 cm (Manege Bosscherhof - Indoor Jumping)>]
>>> for c in Course.objects.filter(event=event).annotate(count_combinations=Count('combination__deleted')):
... c.count_combinations
...
4
8
1
0
2
2
1
1
0
>>> for c in Course.objects.filter(event=event).annotate(count_deleted_combinations=Count('combination__deleted'), count_combinations=Count('combination')):
... c.count_combinations - c.count_deleted_combinations
...
33
29
11
2
1
38
37
21
9
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment