diff --git a/core/models.py b/core/models.py index 0e1a1eb..9f05d9d 100644 --- a/core/models.py +++ b/core/models.py @@ -300,6 +300,18 @@ class Parcel(models.Model): super().save(*args, **kwargs) + @property + def pickup_google_maps_url(self): + if self.pickup_lat and self.pickup_lng: + return f"https://www.google.com/maps/search/?api=1&query={self.pickup_lat},{self.pickup_lng}" + return f"https://www.google.com/maps/search/?api=1&query={self.pickup_address}" + + @property + def delivery_google_maps_url(self): + if self.delivery_lat and self.delivery_lng: + return f"https://www.google.com/maps/search/?api=1&query={self.delivery_lat},{self.delivery_lng}" + return f"https://www.google.com/maps/search/?api=1&query={self.delivery_address}" + def __str__(self): return f"Parcel {self.tracking_number} - {self.status}" diff --git a/core/serializers.py b/core/serializers.py index 415be60..b4cf0be 100644 --- a/core/serializers.py +++ b/core/serializers.py @@ -30,6 +30,8 @@ class ParcelSerializer(serializers.ModelSerializer): delivery_governate_detail = GovernateSerializer(source='delivery_governate', read_only=True) delivery_city_detail = CitySerializer(source='delivery_city', read_only=True) status_display = serializers.CharField(source='get_status_display', read_only=True) + pickup_google_maps_url = serializers.ReadOnlyField() + delivery_google_maps_url = serializers.ReadOnlyField() class Meta: model = Parcel diff --git a/core/templates/core/driver_dashboard.html b/core/templates/core/driver_dashboard.html index 6962256..21eb7e5 100644 --- a/core/templates/core/driver_dashboard.html +++ b/core/templates/core/driver_dashboard.html @@ -198,6 +198,16 @@

{% trans "To" %}: {{ parcel.delivery_governate.name }} / {{ parcel.delivery_city.name }}

{% trans "Receiver" %}: {{ parcel.receiver_name }}

+ +
+ + {% trans "Navigate to Pickup" %} + + + {% trans "Navigate to Delivery" %} + +
+
{% csrf_token %}