|
1 | 1 | import json |
2 | 2 |
|
3 | | -from django.http import HttpResponse, HttpResponseForbidden |
| 3 | +from django.http import HttpResponse, HttpResponseForbidden, JsonResponse |
4 | 4 | from django.shortcuts import get_object_or_404 |
5 | 5 | from myCSSAhub.forms import MerchantsForm |
6 | 6 | from myCSSAhub.models import * |
@@ -37,6 +37,28 @@ def Sponsors(request): |
37 | 37 | jsonRes.append(jsonObj) |
38 | 38 | return HttpResponse(json.dumps(jsonRes), content_type='application/json') |
39 | 39 |
|
| 40 | + |
| 41 | +# New function to get merchant location (longitude and latitude) |
| 42 | +def MerchantLocation(request): |
| 43 | + merchant_id = request.GET.get('id') |
| 44 | + if not merchant_id: |
| 45 | + return JsonResponse({'error': 'Merchant ID is required'}, status=400) |
| 46 | + |
| 47 | + try: |
| 48 | + merchant = DiscountMerchant.objects.get(merchant_id=merchant_id, merchant_type='折扣商家') |
| 49 | + # Assuming merchant_longitude and merchant_latitude fields exist in your model |
| 50 | + location_data = { |
| 51 | + 'id': merchant.merchant_id, |
| 52 | + 'name': merchant.merchant_name, |
| 53 | + 'longitude': merchant.longitude, |
| 54 | + 'latitude': merchant.latitude, |
| 55 | + 'address': merchant.merchant_address |
| 56 | + } |
| 57 | + return JsonResponse(location_data) |
| 58 | + except DiscountMerchant.DoesNotExist: |
| 59 | + return JsonResponse({'error': 'Merchant not found'}, status=404) |
| 60 | + |
| 61 | + |
40 | 62 | # api_view documentation: |
41 | 63 | # https://www.django-rest-framework.org/api-guide/views/ |
42 | 64 | # Specify the POST request, and authenticated user |
|
0 commit comments