Skip to content
This repository has been archived by the owner on Nov 27, 2022. It is now read-only.

Automatically modify Q expression to prepend the aggregated thing #12

Open
mbertheau opened this issue Oct 26, 2014 · 1 comment
Open

Comments

@mbertheau
Copy link

My uses of Count(.., only=..) all look like this:

q_not_expired = Q(...)
products_not_expired = Product.objects.filter(q_not_expired)
qs.annotate(num_published_orders=Count('partner__stockrecords__product',
                                       only=Q(partner__stockrecords__product__in=products_not_expired)))
qs.annotate(registered_participants=Count(
                    'participant', only=Q(participant__status=Participant.REGISTERED)))

So I'm wondering whether it'd make sense to make aggregate-if work such that you can write this instead:

qs.annotate(num_published_orders=Count('partner__stockrecords__product',
                                       only=q_not_expired))
qs.annotate(registered_participants=Count('participant',
                                          only=Q(status=Participant.REGISTERED)))

That way if you have Q-expressions prepared somewhere they can be easily plugged in here.

@henriquebastos
Copy link
Owner

Can you send me a PR with a failing regression test?

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants