On Mon, Aug 18, 2014 at 6:33 PM, Collin Anderson wrote:
>> shows = TVSeries.objects.all().order_by('name').annotate(
>> num_episodes=Count('tvepisode'),
>> num_episodes_with_media=Count('tvepisode__media_id'),
>> num_aired_episodes=Count('tvepisode__airdate'
On Mon, Aug 18, 2014 at 7:17 PM, <9devm...@gmail.com> wrote:
>
>> As an aside, this can probably be written as:
>>
>> current_user_vote = item.vote_set.filter(user=request.user)
>>
>> >
>> > I tried to use annotate() two times, however it filtered out everything
>> > except items current user vo
> As an aside, this can probably be written as:
>
> current_user_vote = item.vote_set.filter(user=request.user)
>
> >
> > I tried to use annotate() two times, however it filtered out everything
> > except items current user voted on.
>
> Just use it once.
>
Thank you for answer, however
> shows = TVSeries.objects.all().order_by('name').annotate(
> num_episodes=Count('tvepisode'),
> num_episodes_with_media=Count('tvepisode__media_id'),
> num_aired_episodes=Count('tvepisode__airdate'),
> num_seasons=Max('tvepisode__season'))
Woah.
On Mon, Aug 18, 2014 at 1:06 PM, <9devm...@gmail.com> wrote:
> Is it possible to annotate two different values to one QuerySet?
>
> Example queryset:
>
> Item.objects.annotate(score=Count('votes'))
Yes, simply pass it as an additional argument to annotate(). An
example from one of my projects:
This one comes up a lot. As far as I can tell, "extra" is the only way to
go.
http://stackoverflow.com/questions/2096580/filtering-only-on-annotations-in-django
http://stackoverflow.com/questions/4620385/django-annotation-with-nested-filter
http://www.djangofoo.com/182/filter-annotate-count
http:/
Is it possible to annotate two different values to one QuerySet?
Example queryset:
Item.objects.annotate(score=Count('votes'))
I would like every item in the above QuerySet to contain the following
field:
current_user_vote = Vote.objects.filter(user=request.user).filter(item=item)
I tried to
7 matches
Mail list logo