Django-endless with a class based example

I am using Class Based Views for the first time. I'm having trouble understanding how, using class-based views, I would do a django-endless-pagination twitter to create a twitter.

Can I give an example of how this can be done?

It's my opinion:

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) 
+4
source share
1 answer

Since this is a broad question, I would like to combine several pagination solutions now.

1. Use a 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 

This will be faster using only urls.py :

 url(r'^entries/$', ListView.as_view(model=Entry, paginate_by=10)) 

So in this solution you do not need django-infinite breakdown. Here you can check out an example template: How to use pagination with Django-based generic ListViews?

2.Use django-endless-pagination 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)) 

Link: http://django-endless-pagination.readthedocs.org/en/latest/generic_views.html

If someone knows a different solution, please comment.

+3
source

Source: https://habr.com/ru/post/1494931/


All Articles