Using django pagination or slicing

126 views
Skip to first unread message

ADEWALE ADISA

unread,
Oct 30, 2016, 9:05:07 PM10/30/16
to django...@googlegroups.com

Hello,
Please I need an advice on the best approach to take on the following issues.
I have a database table consist of about 1000 record. I need to be displaying like 20 records at a time on a page such that when the user scroll the browser another batches will be append to the browser.
Below are the 3 ways am aiming to achieve this:

1. Using django pagination feature.

2. Everytime records need to be appended to the browser , an ajax call is made to the view, then the queryset is slice using appropriate lower and upper band. Then the returned record is appended to the browser.

3. Fetch the whole records from the database and transfer everything to the browser, then JavaScript is now use to slice and be appending as needed.

NOTE: The webpage would work like yahoo.com mobile site.
Please with approach is the best in term of performance and speed.

Thanks.

ludovic coues

unread,
Oct 31, 2016, 4:53:55 AM10/31/16
to django...@googlegroups.com
I would use 1 + 2 from your list.

3 might work on 1000 record, depending on how much data there is per
record. But if you grow to more than 10,000 record, the page loading
can take minutes. I have experienced that issue with two different
project.

Django pagination by itself won't give you the infinite scroll you are
expecting. But it should give you an easy interface for slicing the
data from your db.

An easier way might be class based view. The following exemple create
a view to a list of object, paginated:

from django.http import JsonResponse
from django.views.generic import ListView

class ModelListView(ListView):
model = RecordModel
paginate_by = 20

It will try to use the template at app/record_model_list.html, the
context will have the keys paginator, page, is_paginated, object_list.
You can override the method render_to_response to return a json
response.
The documentation on ListView is at [1] and there is an exemple for
returning JsonResponse at [2]


[1] https://docs.djangoproject.com/en/1.10/topics/class-based-views/generic-display/
[2] https://docs.djangoproject.com/en/1.10/topics/class-based-views/mixins/#more-than-just-html
> --
> 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 post to this group, send email to django...@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/CAMGzuy8cK7ueHGPwuCjbrV-SdfZwkYYhg7_t7-Dmmt%3D6g787YA%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.



--

Cordialement, Coues Ludovic
+336 148 743 42

王安刚

unread,
Oct 31, 2016, 7:01:33 AM10/31/16
to Django users
hi 
i prefer method 2

you can get all the list from db and store it in redis using zadd
each time an ajax request comes, you get the data you need using zrange


在 2016年10月31日星期一 UTC+8上午9:05:07,ADEWALE ADISA写道:

ADEWALE ADISA

unread,
Oct 31, 2016, 10:09:39 AM10/31/16
to django...@googlegroups.com

Thanks very much Ludovic for the advice.


> To post to this group, send email to django...@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/CAMGzuy8cK7ueHGPwuCjbrV-SdfZwkYYhg7_t7-Dmmt%3D6g787YA%40mail.gmail.com.
> For more options, visit https://groups.google.com/d/optout.



--

Cordialement, Coues Ludovic
+336 148 743 42

--
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...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.

ADEWALE ADISA

unread,
Oct 31, 2016, 10:14:02 AM10/31/16
to django...@googlegroups.com

Thanks fedowag.

--
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...@googlegroups.com.
Visit this group at https://groups.google.com/group/django-users.
Reply all
Reply to author
Forward
0 new messages