python - django product of annotate -


django 1.3 python 2.7

i have following models (irrelevant fields omitted):

class encounter(models.model):   subject = models.foreignkey('subject', to_field='uuid')   uuid = models.slugfield(max_length=36, unique=true, default=make_uuid, editable=false)  class subject(models.model):   uuid = models.slugfield(max_length=36, unique=true, default=make_uuid, editable=false)   location = models.foreignkey('location', blank=true, to_field='uuid')  class location(models.model):   uuid = models.slugfield(max_length=36, unique=true, default=make_uuid, editable=false) 

i want know how many encounters occurred @ each location. if encounter contained location field, use annotate(), doesn't , can't add one. know number of encounters per subject , number of subjects per location via annotate(). open combining these multiplicatively wondering a) if works , b) if there better way.

thanks in advance!

seems should work:

location.objects.annotate(encounter_count=count('subject__encounter')) 

Comments

Popular posts from this blog

PHPMotion implementation - URL based videos (Hosted on separate location) -

javascript - Using Windows Media Player as video fallback for video tag -

c# - Unity IoC Lifetime per HttpRequest for UserStore -