randomizing objects in the view with pagination

53 views
Skip to first unread message

John McClain

unread,
Jul 12, 2020, 12:47:07 PM7/12/20
to django...@googlegroups.com
I have a marketplace with many sellers selling the same 3 products in various values. In all the are 18 product type for sell on the platform with hundreds of sellers.

I was randomizing the product category page when loaded so that items from all sellers could appear on the page.

I was not using paginations and I have thousands of products so the page was obviously loading very slow.

I added pagination and let python manage the query instead of it happening on the server-side. This increased the page load but I lost my randomization.

The first page is the only page getting random items loaded. When using pagination to get to the 2nd page the items loading on that page are descending oldest to newest.

Does anyone have an idea how to manage randomizing items on each new page?

I am django core paginator


Any ideas would be appreciated

Cheers,

John 

--
John McClain

Cell: 085-1977-823
Skype: jmcclain0129

MUGOYA DIHFAHSIH

unread,
Jul 12, 2020, 2:58:26 PM7/12/20
to django...@googlegroups.com
Am anxiously waiting for the answer to this question cos i would like to do the same for my django web app

--
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...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/django-users/CAN-hv_qyzZQdCXJBRs_a-3MEt46%3DsOtXvknNuEVBzWNZ_bk5Xg%40mail.gmail.com.

Damanjeet Singh

unread,
Jul 12, 2020, 3:15:22 PM7/12/20
to django...@googlegroups.com
Hello,

I have been using random module (django-random-queryset)  for site https://www.euroautozone.com. Performance is not bad.

here is the code

models.py 
class product(models.Model):
##Slug
objects = RandomManager()
Views.py
       query = product.objects.filter(Q(title__icontains=query)
                                              |
Q(description__icontains=query)
|
Q(customLabel__icontains=query)
|
Q(advertiserName__icontains=query)
|
Q(brand__icontains=query)
).filter(siteName__icontains=getCurrentSite(request)).distinct()

all_information=query.random(1000)

Regards,
Damanjeet

Reply all
Reply to author
Forward
0 new messages