How can I implement Ajax pagination without side modules like endless-pagination

2014-10-06 Thread Artie
I need to make ajax pagination in my project and not allowed to use side 
modules like dajax or endless-pagination.

Code in my views.py is following
def listing(request):
news_list = NewPost.objects.all()
paginator = Paginator(news_list, 2)

page = request.GET.get('page')
try:
news = paginator.page(page)
except PageNotAnInteger:
news = paginator.page(1)
except EmptyPage:
news = paginator.page(paginator.num_pages)

return render_to_response('list.html', {"news": news})
Need to load new pages with AJAX

How it should be done?

-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/059aff43-9578-4265-8cd0-21e900b83d97%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.


Re: How can I implement Ajax pagination without side modules like endless-pagination

2014-10-06 Thread Collin Anderson
copy/pasting from a recent website I worked on for an example...
we actually just had a "load more" button without showing the total number 
of pages. Not saying you should do it this way, but it's one possible way.

def listing(request):
new_list = NewPost.objects.all()
if request.GET.get('before'):
new_list = new_list.filter(post_date__lte=request.GET.get('before'))
num_posts = 6
items = list(new_list[:num_posts + 1])
return render('list.html', {'news': items[:num_posts], 'more': items[
num_posts:]})



{% for item in news %}
{{ item }} etc 
{% endfor %}
{% if more %}
Load More
{% end if %}


 // assuming jQuery is on the page
$(document).on('click', '.js-load-more', function(e){
e.preventDefault();
var more_link = this;
$.get(this.href, function(data){
$(more_link).replaceWith($($.parseHTML(data)).find('.js-items').
children());
})
})


-- 
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+unsubscr...@googlegroups.com.
To post to this group, send email to django-users@googlegroups.com.
Visit this group at http://groups.google.com/group/django-users.
To view this discussion on the web visit 
https://groups.google.com/d/msgid/django-users/0757add7-a622-4ddf-97a7-c91b89b75fee%40googlegroups.com.
For more options, visit https://groups.google.com/d/optout.