Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- def get_list_locations(request):
- account = Account.objects.get(user=request.user)
- street = request.GET.get('street', '')
- number_building = request.GET.get('num', '')
- sub_polyclinic = request.GET.get('bra', '')
- polyclinic = account.polyclinic.get()
- if sub_polyclinic == '':
- sub_polyclinic = Subdivision_Polyclinic.objects.get(polyclinic = account.polyclinic.get())
- sub_polyclinic = sub_polyclinic.branch
- location = Location.objects.select_related('subdivision_polyclinics', 'polyclinic')
- if street:
- locations = location.filter(street__icontains = street)
- if number_building:
- locations = location.filter(building__icontains = number_building)
- if sub_polyclinic:
- locations = location.filter(subdivision_polyclinics__branch=sub_polyclinic)
- if not locations:
- locations = location.filter(chek_building = False,subdivision_polyclinics__branch=sub_polyclinic, polyclinic__id = polyclinic.id)
- locations_json = []
- for i in locations:
- if(chek_write(i.polyclinic.id)):
- locations_json.append({'polyclinic': str(i.polyclinic.name),'building': str(i.building), 'branch': i.subdivision_polyclinics.name_sub,
- 'street': str(i.street),'zone': str(i.zone), 'email': str(i.polyclinic.email),
- 'contact': str(i.polyclinic.contact), 'recording': set_or_redirect(i)})
- return HttpResponse(json.dumps(locations_json), content_type='application/json')
- ====================== Твой код ==================================
- def get_list_locations(request):
- account = Account.objects.get(user=request.user)
- street = request.GET.get('street', '')
- number_building = request.GET.get('num', '')
- sub_polyclinic = request.GET.get('bra', '')
- polyclinic = account.polyclinic.get()
- if sub_polyclinic == '':
- sub_polyclinic = Subdivision_Polyclinic.objects.get(polyclinic = account.polyclinic.get())
- sub_polyclinic = sub_polyclinic.branch
- location = Location.objects.select_related('subdivision_polyclinics', 'polyclinic')
- if len(number_building) == 0:
- locations = location.filter(
- street__icontains=street,
- subdivision_polyclinics__branch=sub_polyclinic,
- polyclinic__id = polyclinic.id)
- else:
- locations = location.filter(
- Q (street__icontains=street)
- & Q (building__icontains=number_building)
- & Q (subdivision_polyclinics__branch=sub_polyclinic)
- & Q (polyclinic__id = polyclinic.id))
- if not locations:
- locations = location.filter(
- street__icontains=street,
- chek_building = False,
- subdivision_polyclinics__branch=sub_polyclinic,
- polyclinic__id = polyclinic.id)
- locations_json = []
- for i in locations:
- if(chek_write(i.polyclinic.id)):
- locations_json.append({'polyclinic': str(i.polyclinic.name),'building': str(i.building), 'branch': i.subdivision_polyclinics.name_sub,
- 'street': str(i.street),'zone': str(i.zone), 'email': str(i.polyclinic.email),
- 'contact': str(i.polyclinic.contact), 'recording': set_or_redirect(i)})
- return HttpResponse(json.dumps(locations_json), content_type='application/json')
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement