FAQ Database Discussion Community


Django pagination in filtered search post results

django,django-pagination
I have a view that filters out results for a posted search form: def profile_advanced_search(request): args = {} if request.method == "POST": form = AdvancedSearchForm(request.POST) qs=[] if form.is_valid(): cd = form.cleaned_data s_country=cd['country'] s_province=cd['province'] s_city = cd['city'] if s_country: qs.append(Q(country__icontains = s_country)) if s_province: qs.append( Q(province__icontains=s_province)) if s_city: qs.append( Q(city__icontains=s_city)) f...

Pagination in Django-Rest-Framework using API-View

django,django-rest-framework,django-pagination
I currently have an API view setup as follows: class CartView(APIView): authentication_classes = [SessionAuthentication, TokenAuthentication] permission_classes = [IsAuthenticated, ] api_view = ['GET', 'POST'] def get(self, request, format=None): try: cart = request.user.cart except Cart.DoesNotExist: cart = Cart.objects.create(user=request.user) cart_details = cart.cart_details.all() serializer = CartDetailSerializer(cart_details, many=True, fields=['id', 'item', 'quantity', 'product_type']) return Response(serializer.data) Here...

Display only some of the page numbers by django pagination

django,django-pagination
I am using the django paginator in the template. Its working ok, but not good when there's large numbers of pages. views.py: def blog(request): blogs_list = Blog.objects.all() paginator = Paginator(blogs_list, 1) try: page = int(request.GET.get('page', '1')) except: page = 1 try: blogs = paginator.page(page) except(EmptyPage, InvalidPage): blogs = paginator.page(page) return...

Filtering is not happening in the next page

python-2.7,django-views,django-filter,django-pagination
I have added pagination in my view. The pagination is working fine but when I am filtering my data and navigate to the next page it is not paginating through the filtered data, it goes to the actual next where filtering is not happened, here is my views and template...