def ajax_list(self): field = request.params.get('field') prev_page = 0 next_page = 0 try: models = path_to_models(self.model, field) except AttributeError: data = [] else: rel_model = models.pop() rel_field = rel_model._meta.fields[self.foreign_key_lookups[field]] query = rel_model.select().order_by(rel_field) query_string = request.params.get('query') if query_string: query = query.where(rel_field ** ('%%%s%%' % query_string)) pq = PaginatedQuery(query, self.filter_paginate_by) current_page = pq.get_page() if current_page > 1: prev_page = current_page - 1 if current_page < pq.get_pages(): next_page = current_page + 1 data = [ {'id': obj.get_id(), 'repr': unicode(obj)} \ for obj in pq.get_list() ] Response.headers['mimetype'] = 'application/json' return {'prev_page': prev_page, 'next_page': next_page, 'object_list': data}
def paginated_object_list(self, filtered_query): try: paginate_by = int(request.params.get('limit', self.paginate_by)) except ValueError: paginate_by = self.paginate_by else: if self.paginate_by: paginate_by = min(paginate_by, self.paginate_by) # restrict pq = PaginatedQuery(filtered_query, paginate_by) meta_data = self.get_request_metadata(pq) query_dict = self.serialize_query(pq.get_list()) return self.response({ 'meta': meta_data, 'objects': query_dict, })