def ajax_list(self): field = request.args.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.args.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() ] json_data = json.dumps({'prev_page': prev_page, 'next_page': next_page, 'object_list': data}) return Response(json_data, mimetype='application/json')
def ajax_list(self): field_name = request.args.get('field') prev_page = 0 next_page = 0 try: models = path_to_models(self.model, field_name) except AttributeError: data = [] else: field = self.model._meta.fields[field_name] rel_model = models.pop() rel_field = rel_model._meta.fields[self.foreign_key_lookups[field_name]] query = rel_model.select().order_by(rel_field) query_string = request.args.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 = [] # if the field is nullable, include the "None" option at the top of the list if field.null: data.append({'id': '__None', 'repr': 'None'}) data.extend([{'id': obj.get_id(), 'repr': unicode(obj)} for obj in pq.get_list()]) json_data = json.dumps({'prev_page': prev_page, 'next_page': next_page, 'object_list': data}) return Response(json_data, mimetype='application/json')
def ajax_list(self): field = request.args.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 = self.foreign_key_lookups[field] query = rel_model.select().where(**{ '%s__icontains'% rel_field: request.args.get('query', ''), }).order_by(rel_field) 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_pk(), 'repr': unicode(obj)} \ for obj in pq.get_list() ] json_data = json.dumps({'prev_page': prev_page, 'next_page': next_page, 'object_list': data}) return Response(json_data, mimetype='application/json')
def ajax_list(self): field = request.args.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 = self.foreign_key_lookups[field] query = ( rel_model.select() .where(**{"%s__icontains" % rel_field: request.args.get("query", "")}) .order_by(rel_field) ) 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_pk(), "repr": unicode(obj)} for obj in pq.get_list()] json_data = json.dumps({"prev_page": prev_page, "next_page": next_page, "object_list": data}) return Response(json_data, mimetype="application/json")
def ajax_list(self): field_name = request.args.get('field') prev_page = 0 next_page = 0 try: models = path_to_models(self.model, field_name) except AttributeError: data = [] else: field = self.model._meta.fields[field_name] rel_model = models.pop() rel_field = rel_model._meta.fields[ self.foreign_key_lookups[field_name]] query = rel_model.select().order_by(rel_field) query_string = request.args.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 = [] # if the field is nullable, include the "None" option at the top of the list if field.null: data.append({'id': '__None', 'repr': 'None'}) data.extend([{ 'id': obj._pk, 'repr': str(obj) } for obj in pq.get_list()]) json_data = json.dumps( { 'prev_page': prev_page, 'next_page': next_page, 'object_list': data }, cls=StringifyingEncoder) return Response(json_data, mimetype='application/json')