newmediamonitoring/polls/views/compartment.py

22 lines
721 B
Python
Raw Normal View History

2020-09-20 11:14:54 +00:00
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):
parent_code = request.GET.get('pcode', '620000000000')
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)