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.
>
> >
>
>
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=Su
Thank you, Todor. I'll try.
вторник, 23 мая 2017 г., 3:27:00 UTC+5 пользователь Todor Velichkov написал:
>
> 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 4
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')
Andrew, your solution works great for one brand. But I have more than one.
суббота, 20 мая 2017 г., 0:20:18 UTC+5 пользователь Andrew Beales написал:
>
> brand = Brand.objects.get(title='mybrand')
> products = Product.objects.filter(brand=brand).order_by('-score')[:4]
>
> ...gets you the top 4 pro
brand = Brand.objects.get(title='mybrand')
products = Product.objects.filter(brand=brand).order_by('-score')[:4]
...gets you the top 4 products in order for the brand
On Friday, May 19, 2017 at 10:32:49 AM UTC+1, Горобец Дмитрий wrote:
>
> Hello. I have these two models. I have to show 4 or less
6 matches
Mail list logo