mortezaei 5 months ago
parent
commit
b46dbb5c82
  1. 14
      apps/account/serializers/location_history.py
  2. 2
      apps/account/views/location_history.py

14
apps/account/serializers/location_history.py

@ -22,4 +22,16 @@ class ReverseGeolocationSerializer(serializers.Serializer):
min_value=-180.0, min_value=-180.0,
max_value=180.0, max_value=180.0,
help_text="Longitude coordinate (-180 to 180)" help_text="Longitude coordinate (-180 to 180)"
)
)
class ReverseGeolocationResponseSerializer(serializers.Serializer):
"""Serializer for reverse geolocation response"""
latitude = serializers.FloatField(read_only=True)
longitude = serializers.FloatField(read_only=True)
city = serializers.CharField(max_length=100, allow_null=True, read_only=True)
country = serializers.CharField(max_length=100, allow_null=True, read_only=True)
country_code = serializers.CharField(max_length=10, allow_null=True, read_only=True)
accuracy_radius = serializers.IntegerField(allow_null=True, read_only=True, required=False)
time_zone = serializers.CharField(max_length=100, allow_null=True, allow_blank=True, read_only=True, required=False)
postal_code = serializers.CharField(max_length=20, allow_null=True, allow_blank=True, read_only=True, required=False)

2
apps/account/views/location_history.py

@ -9,7 +9,7 @@ from rest_framework.response import Response
from rest_framework.views import APIView from rest_framework.views import APIView
from rest_framework import status from rest_framework import status
from apps.account.models import LocationHistory from apps.account.models import LocationHistory
from apps.account.serializers import LocationHistorySerializer, ReverseGeolocationSerializer
from apps.account.serializers import LocationHistorySerializer, ReverseGeolocationSerializer, ReverseGeolocationResponseSerializer
import geoip2.database import geoip2.database
import geoip2.errors import geoip2.errors
from city_detection_ip import get_location_by_coordinates, get_location_by_ip, SPECIAL_COORDINATES from city_detection_ip import get_location_by_coordinates, get_location_by_ip, SPECIAL_COORDINATES

Loading…
Cancel
Save