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 the
    view 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` argument
        in 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 ListView
class EntryList(ListView):
    model = Entry
    template_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 = Entry
    context_object_name = 'entry_list'
    page_template = 'entry.html'
Or faster (again) with urls.py only:
from endless_pagination.views import AjaxListView
url(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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With