Thursday, May 25, 2017

Re: Building correct queryset

Score field is on Brand model.

пятница, 26 мая 2017 г., 3:19:56 UTC+5 пользователь Melvyn Sopacua написал:

On Monday 22 May 2017 15:26:59 Todor Velichkov wrote:

> Hello, Ð"митрий,

> you can try this one, but w/o further optimizations it may be a very

> slow query.

>

> qs = Product.objects.filter(

> #Where score is greater or equal

> #to the 4th max score from its group

> score__gte=Subquery(

> (Product.objects

> .filter(brand=OuterRef('brand'))

> .values('score')

> .order_by('-score')[3:4]

> )

> )

> ).order_by('-score')

 

Yeah, that's how I read it too. But the code says score is on Brand model, not Product. Which is correct?

--

Melvyn Sopacua

--
You received this message because you are subscribed to the Google Groups "Django users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to django-users+unsubscribe@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/5838210b-f4ea-4338-ab2c-7c6e706acae2%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

No comments:

Post a Comment