On Wednesday, February 23, 2011 7:28:06 PM UTC+1, Patrick wrote:
>
> Hi, 
>
> i am trying to compare two count-annotations with a simple "greater- 
> than" filter like this: 
> ResultSequence.objects.annotate(num_result=Count('resultset'),num_part=Count('seminar__participant')).filter(num_result__gt=num_part)
>  
>
> i also tried doing it like this: 
> ResultSequence.objects.annotate(num_result=Count('resultset')).annotate(num_part=Count('seminar__participant')).filter(num_result__gt=num_part)
>  
>
> both ways return "NameError: name 'num_part' is not defined" 
>
> it seems to be working nicely when i manually set the last parameter: 
> ResultSequence.objects.annotate(num_result=Count('resultset'),num_part=Count('seminar__participant')).filter(num_result__gt=15)
>  
>
>
> i dont know if i misunderstand the whole concept of "annotate" or if 
> this is just impossible to do.. 
>
> thanks in advance 
> patrick


The problem is not the annotations, but any time you need to use a field 
value on the right-hand side. See the documentation on this:
http://docs.djangoproject.com/en/1.2/topics/db/queries/#filters-can-reference-fields-on-the-model
--
DR. 

-- 
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 
django-users+unsubscr...@googlegroups.com.
For more options, visit this group at 
http://groups.google.com/group/django-users?hl=en.

Reply via email to