from django.shortcuts import render from dashboard.models import Area_code_2020 from django.http import JsonResponse from django.views.decorators.csrf import csrf_exempt from polls.decorators import polls_login_required @csrf_exempt @polls_login_required def compartments(request): level = request.GET.get('level') parent_code = request.GET.get('code', '620000000000') if level == '2': compartments = Area_code_2020.objects.filter(code=parent_code) else: compartments = Area_code_2020.objects.filter(pcode=parent_code) results = [] for o in compartments: result = dict() result['code'] = o.code result['name'] = o.name result['level'] = o.level result['pcode'] = o.pcode results.append(result) return JsonResponse({'status': 'success', 'message': results}, safe=False)