feat: Add Google Maps navigation links for drivers

- Added  and  properties to  model.
- Exposed these URLs in .
- Updated driver dashboard to show 'Navigate to Pickup' and 'Navigate to Delivery' buttons for active shipments.
This commit is contained in:
Flatlogic Bot 2026-02-01 04:20:12 +00:00
parent f1de11cc52
commit bf29a0b21b
3 changed files with 24 additions and 0 deletions

View File

@ -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}"

View File

@ -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

View File

@ -198,6 +198,16 @@
<p class="card-text mb-1 small"><strong>{% trans "To" %}:</strong> {{ parcel.delivery_governate.name }} / {{ parcel.delivery_city.name }}</p>
<p class="card-text mb-3 small"><strong>{% trans "Receiver" %}:</strong> {{ parcel.receiver_name }}</p>
<!-- Google Maps Navigation Buttons -->
<div class="d-grid gap-2 mb-3">
<a href="{{ parcel.pickup_google_maps_url }}" target="_blank" class="btn btn-outline-primary btn-sm">
<i class="bi bi-geo-alt-fill me-1"></i> {% trans "Navigate to Pickup" %}
</a>
<a href="{{ parcel.delivery_google_maps_url }}" target="_blank" class="btn btn-outline-success btn-sm">
<i class="bi bi-geo-alt-fill me-1"></i> {% trans "Navigate to Delivery" %}
</a>
</div>
<form action="{% url 'update_status' parcel.id %}" method="POST" class="d-flex gap-2">
{% csrf_token %}
<select name="status" class="form-select form-select-sm">