46 lines
1.3 KiB
Python
46 lines
1.3 KiB
Python
|
from django.shortcuts import render
|
||
|
from dashboard.models import Organization
|
||
|
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 organizations(request):
|
||
|
category = request.GET.get('category', '1')
|
||
|
code = request.GET.get('code')
|
||
|
print(category, code)
|
||
|
if category == '1':
|
||
|
organizations = Organization.objects.exclude(
|
||
|
province=''
|
||
|
).filter(
|
||
|
cities='',
|
||
|
district=''
|
||
|
)
|
||
|
elif category == '2':
|
||
|
organizations = Organization.objects.exclude(
|
||
|
province=''
|
||
|
).filter(
|
||
|
cities=code,
|
||
|
district=''
|
||
|
)
|
||
|
elif category == '3':
|
||
|
organizations = Organization.objects.exclude(
|
||
|
province='',
|
||
|
cities='',
|
||
|
).filter(
|
||
|
district=code
|
||
|
)
|
||
|
results = []
|
||
|
for o in organizations:
|
||
|
result = dict()
|
||
|
result['id'] = o.id
|
||
|
result['name'] = o.name
|
||
|
result['province'] = o.province
|
||
|
result['cities'] = o.cities
|
||
|
result['district'] = o.district
|
||
|
results.append(result)
|
||
|
|
||
|
return JsonResponse({'status': 'success', 'message': results}, safe=False)
|