I'm using Class Based Views for the first time. I'm having trouble understating how using class based views I would implement django-endless-pagination twitter styling paging.
Could I have an example of how one would go about this?
This is my view:
class EntryDetail(DetailView):"""Render a "detail" view of an object.By default this is a model instance looked up from `self.queryset`, but theview will support display of *any* object by overriding `self.get_object()`."""context_object_name = 'entry'template_name = "blog/entry.html"slug_field = 'slug'slug_url_kwarg = 'slug'def get_object(self, query_set=None):"""Returns the object the view is displaying.By default this requires `self.queryset` and a `pk` or `slug` argumentin the URLconf, but subclasses can override this to return any object."""slug = self.kwargs.get(self.slug_url_kwarg, None)return get_object_or_404(Entry, slug=slug)
Since this is a broad question, I would like to combine several solutions for pagination now.
1.Use the generic ListView:
from django.views.generic import ListViewclass EntryList(ListView):model = Entrytemplate_name = 'blog/entry_list.html'context_object_name = 'entry_list'paginate_by = 10
It would be way faster using only urls.py
:
url(r'^entries/$', ListView.as_view(model=Entry, paginate_by=10))
So basically you don't need django-endless-pagination in this solution. You can check the example of template here: How do I use pagination with Django class based generic ListViews?
2.Use django-endless-pagination's AjaxListView:
from endless_pagination.views import AjaxListView
class EntryList(AjaxListView):model = Entrycontext_object_name = 'entry_list'page_template = 'entry.html'
Or faster (again) with urls.py
only:
from endless_pagination.views import AjaxListViewurl(r'^entries/$', AjaxListView.as_view(model=Entry))
Reference: http://django-endless-pagination.readthedocs.org/en/latest/generic_views.html
If anyone knows different solution, please comment.