mirror of
				https://github.com/encode/django-rest-framework.git
				synced 2025-11-04 09:57:55 +03:00 
			
		
		
		
	Set self.count before self.limit in LimitOffsetPagination
By doing this it is possible to override get_limit in order to return all records if the request has a predefined param. For example, if one wants that all records are retrieved if url has &limit=-1, get_limit could return self.count in this case. Otherwise, if self.count is set after self.limit then, to achive the same result, one has to override get_limit and paginate_queryset, or run get_limit twice.
This commit is contained in:
		
							parent
							
								
									f064ec6ac6
								
							
						
					
					
						commit
						ec4761225e
					
				| 
						 | 
					@ -303,12 +303,12 @@ class LimitOffsetPagination(BasePagination):
 | 
				
			||||||
    template = 'rest_framework/pagination/numbers.html'
 | 
					    template = 'rest_framework/pagination/numbers.html'
 | 
				
			||||||
 | 
					
 | 
				
			||||||
    def paginate_queryset(self, queryset, request, view=None):
 | 
					    def paginate_queryset(self, queryset, request, view=None):
 | 
				
			||||||
 | 
					        self.count = _get_count(queryset)
 | 
				
			||||||
        self.limit = self.get_limit(request)
 | 
					        self.limit = self.get_limit(request)
 | 
				
			||||||
        if self.limit is None:
 | 
					        if self.limit is None:
 | 
				
			||||||
            return None
 | 
					            return None
 | 
				
			||||||
 | 
					
 | 
				
			||||||
        self.offset = self.get_offset(request)
 | 
					        self.offset = self.get_offset(request)
 | 
				
			||||||
        self.count = _get_count(queryset)
 | 
					 | 
				
			||||||
        self.request = request
 | 
					        self.request = request
 | 
				
			||||||
        if self.count > self.limit and self.template is not None:
 | 
					        if self.count > self.limit and self.template is not None:
 | 
				
			||||||
            self.display_page_controls = True
 | 
					            self.display_page_controls = True
 | 
				
			||||||
| 
						 | 
					
 | 
				
			||||||
		Loading…
	
		Reference in New Issue
	
	Block a user